. Python 2.1 function attributes

Rainer Deyke root at rainerdeyke.com
Sat Jan 27 10:53:07 EST 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.980593892.725.python-list at python.org...
> def f():
>     pass
> f.attr = 0

If AttributeDecorator (see a previous post in this thread) was part of the
standard library, the following could be used:

def f():
  pass
f = AttributeDecorator(f, attr=0)

This is more general than function attributes and just as obvious and
powerful.  The real drawback of function-like objects is that they are not
bound as methods:

class A:
  def f(self): pass
  f = AttributeDecorator(f, attr=0)

A().f() # Fails because f is not a true function.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list