Invisible function attributes
John J. Lee
jjl at pobox.com
Thu Sep 4 01:16:01 CEST 2003
lefevrol at yahoo.com (Olivier Lefevre) writes:
> So it would appear that function attributes are not really
> there until the first call to the function. If that is the
Not function attributes in general, just those that are first assigned
to in the function body. No special rule here, though, because...
> intended behaviour, it is really weird. I couldn't find any
> explicit discussion of this topic in the LRM.
> Thanks if anyone can shed some light on this,
...what I'm guessing you haven't figured out yet is that everything
works like this in Python. For example, what might be called a 'class
declaration' in other languages isn't really a declaration in Python,
it's code that gets executed at runtime. Same is true of functions:
def sayhello(): print "spam"
def sayhello(): print "eggs"
And your foo.a = 1 isn't a declaration (Python doesn't have them,
really), it's just an attribute assignment.
More information about the Python-list