Decorator syntax

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Sun Aug 8 01:49:37 CEST 2004


Yawar Amin wrote:
> How about
> 
> def foo(a, b, c):
>      foo.accepts = (int, int, list)
>      foo.author = 'Chris King'

That already has a different meaning: Function foo sets those attributes
on itself each time it is called.  They should be set once, before the
function is called.

$ python2.3
>>> def foo(a, b, c):
...      foo.accepts = (int, int, list)
...      foo.author = 'Chris King'
... 
>>> foo.author
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'function' object has no attribute 'author'
>>> foo(1,2,3)
>>> foo.author
'Chris King'

-- 
Hallvard



More information about the Python-list mailing list