Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Sat, 11 Aug 2007 20:30:54 +0200, Helmut Jarausch wrote: > >> are decorators more than just syntactic sugar in python 2.x and what >> about python 3k ? > > They are just syntactic sugar. > > @spam > def ham(): > pass > > is the same as > > def ham(): > pass > > ham = spam(ham)
Decorators are almost just syntactic sugar, but in fact there is a subtle difference between the two bits of code you gave: in the second one you assign the function to the name ham and then replace it with the result of calling spam. With the decorator syntax you only have one assignment to ham and when that decorator is called that assignment has not yet happened. The difference is small, but you can write decorators which depend on it. For example, the code I posted in <[EMAIL PROTECTED]> depends on this difference and will not work if you write the calls out explicitly instead of using decorators. -- http://mail.python.org/mailman/listinfo/python-list