what is meaning of "@" in pyhon program.

Mike Driscoll kyosohma at gmail.com
Fri Jun 27 17:03:19 CEST 2008


On Jun 27, 9:48 am, Evan <xdi... at gmail.com> wrote:
> HI,
>
> When I check example of "cmd2" module (a enhancement of cmd module), I
> can not understand all, for example: the  character "@",
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
> def options(option_list):
>      ..........<function content>........
>
> class cmd(...):
>     ...............................
>     @options([make_option('-p', '--piglatin', action="store_true",
> help="atinLay")])
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> I do not understand what "@options" does,   most time, I know what the
> meaning of character "*" and character "**", but I was not use "@"
> before.
>
> Thanks for your help.

The "@" sign is there to signify that what follows is a decorator.
They're kind of cool and kind of confusing. Basically they dynamically
alter a function, method or class and gives them additional
functionality. It's kind of like calling a function recursively. Check
out the following links:

http://www.python.org/dev/peps/pep-0318/
http://wiki.python.org/moin/PythonDecorators
http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

Mike



More information about the Python-list mailing list