namespace query

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Apr 22 08:33:04 EDT 2009


On Wed, 22 Apr 2009 05:21:06 -0700, Dr Mephesto wrote:

> If I add a "global numpy" to the beginning of each class in the new
> files, the program runs. Do I really have to add "global XXX" for every
> module I import in the main program into every module I create and
> import? Why are the class files I created not seeing the top namespace?

What's the top namespace?

Every Python module is a namespace. The module namespace is flat: all 
modules are at the same level. A module can't know what other modules 
have imported it, and code in the imported module can't see the importing 
namespace.

However, you can get something like a hierarchical namespace by using 
packages. Possibly this might accomplish what you are trying to do.

http://docs.python.org/tutorial/modules.html#packages



-- 
Steven



More information about the Python-list mailing list