(no subject)
Alex Martelli
aleax at aleax.it
Fri Jan 25 09:03:53 EST 2002
"sail" <raise_sail at sina.com> wrote in message
news:mailman.1011889136.20179.python-list at python.org...
> hello all,
> I am reading the "Python ref-Man" after Tutorial , this is I read it
> second. the first time, I can not understand it all, but I think I must
read again in future. so Now , I reading. :), have a bit verbosity.
> I have two questions about function Special attributes:
>
> 1. what is mean of attrib func_dict or __dict__? I defined a function
> Afunc() as follow:
> def Afunc():
> """ A func example"""
> print "Afunc"
>
> why Afunc.__dict__ is {} ??? I do not know.
Afunc.__dict__ is an empty dictionary because you set no extra, ad-hoc
attributes on object Afunc. When you do, the dictionary's used:
>>> def Afunc(): print 'Afunc'
...
>>> Afunc.__dict__
{}
>>> Afunc.anattribute = 23
>>> Afunc.__dict__
{'anattribute': 23}
>>>
> 2. like above, I can not know the attrib func_closure. in manual ,
> this say " free variables", I did not saw it ago at all.
This has to do with "nested scopes". If a function is nested inside
another, it can access (NOT re-bind) local functions of the functions
it is nested in. To allow this, the function object must have a
way to find out the one it's directly nested in (if any), and this
is accomplished through the func_closure attribute.
You don't really need to master such stuff to use Python excellently
well, by the way. The Python Reference manual IS meant for
"language lawyers". Read the *Library* manual instead, THAT one
is chock full of preciously useful information.
Alex
More information about the Python-list
mailing list