Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

wineColoredDays's blog

By wineColoredDays, history, 8 years ago, In English

To all the Python Gods out there, can you please explain the concept of decorators in Python.

I need to understand how it works, what are its advantages, how can be it applied over functions and classes. And hold, how you keep track when there are multiple decorators applied to the same class or function. I mean how you visualize.

Thanks in advance :)

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

.....waiting....

»
8 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Basically this question is quite large, but actually I don't see possible use cases of this pattern in competitive programming (except for some kind of 'memo' decorators, probably)

Anyway I guess that simplest way to describe how it works is to see what are common use cases: https://www.quora.com/What-are-common-uses-of-Python-decorators Additionally, you can read PEP 318: https://www.python.org/dev/peps/pep-0318/

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I came across decorators while going through a code base in my job, it has nothing to do with CP. Thanks, though :)