__metaclass__ and __author__ are already decorators
Leif K-Brooks
eurleif at ecritters.biz
Sat Aug 21 19:40:02 EDT 2004
Paul Morrow wrote:
> And I don't agree that this would be assigning new 'meaning' to an old
> syntax. When a programmer creates a __xxx__ class attribute, he is not
> trying to create a normal 'class' attribute --- one the is inherited by
> instances of the class or that holds part of the 'state' of the class.
> Instead, he is trying to make a meta statement about the class (who
> wrote it, what happens during instance initialization, etc.). In that
> sense, the meaning associated with defining __xxx__ attributes would
> stay the same.
If we were talking about something like this:
def foo(self):
pass
foo.__author__ = "Leif K-Brooks"
then you would be correct. But when syntax normally used for assigning
to a variable magically assigns to an attribute if the variable name
starts and ends with "__", then it's an existing syntax (variable
assignment) being used for something new (attribute assignment). Why
should this:
def foo(self):
bar = 42
mean anything different from this?
def foo(self):
__bar__ = 42
More information about the Python-list
mailing list