[Q] Namespaces

Siew-Ann Cheong cheong at msc.cornell.edu
Mon May 28 00:30:00 EDT 2001


Hi,

I noticed the following:

If I have moduleA.py and moduleB.py, such that the functions defined in
moduleB uses those defined in moduleA, an "import moduleA" statement is
necessary in moduleB.py.

If now moduleB is imported into the interpreter, moduleA functions appear
in the namespace of moduleB.

There are situations where moduleA itself will be imported directly, but
this appears under the __main__ namespace.

My question is: is it possible to perform some sort of check for existing
moduleA functions when importing moduleB, and import moduleA either into
the main namespace or the moduleB namespace only when moduleA has not been
loaded?  Something like the #ifndef preprocessor statements in C/C++?

Thanks!


Cheong Siew Ann



More information about the Python-list mailing list