A new to Python question

Bengt Richter bokr at oz.net
Sat May 14 17:06:35 EDT 2005


On 14 May 2005 10:44:30 -0700, "M.E.Farmer" <mefjr75 at hotmail.com> wrote:
[...]
>Be sure to study up on namespaces, it will ease your Python woes.
>Namespaces are the most fundamental part of Python that new users don't
>understand. Namespace mastery will take you far.
>Just remember there are only two scopes local and global ;)
And don't jump to conclusions when you read a line like the last above ;-)
I.e., there can be many different local and global scopes, not just one of each,
and since Python is a very dynamic language, existence of things can vary with
execution time and logic, so those scopes don't all have to exist at the same time,
or at all, nor persist until the program runs to its end. Also, ISTM "local" is probably
being stretched a little above to include nested scopes, which are a bit different
from either plain local or global in how you can access them.

I would second the advice to explore namespaces, and particularly attribute name spaces
such as are defined by classes. Attribute access and descriptors conspire to enable much
of the magic you can cook up with Python, as well as stuff that happens automatically.

In short, a whole unopened deluxe set of programming Legos is at your elbow, besides the
pieces you have encountered so far. Have fun ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list