what is meaning of "@" in pyhon program.
bruno.42.desthuilliers at websiteburo.invalid
Fri Jun 27 17:09:51 CEST 2008
Mike Driscoll a écrit :
> On Jun 27, 9:48 am, Evan <xdi... at gmail.com> wrote:
>> 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",
>> I do not understand what "@options" does, most time, I know what the
>> meaning of character "*" and character "**", but I was not use "@"
>> 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.
Mostly, it's just syntactic sugar for an higher order function. IOW, given:
# do anythin you wish here
# and return any callable object
the two following syntaxes are equivalent:
toto = deco(toto)
More information about the Python-list