I've been coding in python and using classes so I have things pretty sewn up in namespaces.
Do you know about modules and packages? Classes aren't the only things that create namespaces in python.
I'm trying to figure out how I would test this assumption!
Hmmm...do you recognize a distinction between scope and namespace? I guess a base namespace would be the top package in a package/module hierarchy that you created. On the other hand, if you don't have a package hierarchy then you should be aware that every python file is a module; and every variable, function, and class is namespaced by the module name.
As far as scope goes, it's the famous LEGB. And for __main__, the docs say:
__main__ — Top-level script environment
This module represents the (otherwise anonymous) scope in which the interpreter’s main program executes
...which seems to indicate a scope hierarchy of LEGB__main__, which, in my opinion, is just gobbledygook, with the only practical application I know of being:
- Code: Select all
if __name__ = "__main__":
#The following code will run if this file was specified as the argument to `python`.