Python - Decorators

| Page Views: 42

Decorators decorate functions. They themselves are functions that accept a function and return a function.

Decorators get applied using a special syntax.

@suppress_errors
def show_errors():
    pass

In the above the decorator is the @suppress_errors statement.

Decorators are important in that they allow a set of common tasks to be performed by many different functions, ususlaly before or after doing something more specific to the target function.

Common areas where decorators get applied include: access control, error handling, caching, logging, mapping routes to functions etc.

Without decorators you would need to copy code several times to perform that task before or after the target function is executed.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.




Recommendations


What do You Think


Previous Post Next Post