Name space quirk?

NANDYALA D Gangadhar n_d_gangadhar at yahoo.com
Mon Jul 23 09:57:31 EDT 2001


Hi, Alex.

[Hope I am not bugging you!]

I understand what you said. So I have:

1. Before one uses a name in __main__, one has to make sure that it is
   not used anywhere in the Module, even without the qualifier "global";
   failure to do so could be unpleasent.
   
2. OTOH, __main__ namespace is not searched by the module if it is 
   imported, since it is only __builtins__ that is searched, after 
   the module's name space. Hence, I get NameError with 

nspace1.py:

#!/usr/bin/env python

from nspace import *
 
if __name__ == '__main__':
        f = sys.argv[0] + ".out"
        myfile = open (f, 'w')
        hello (myfile)

[myfile was declared global in nspace.py] in interactive mode as well.

To be frank, though this is in accordance with the reference, it is
not, IMO, (for want of a better word) "consistent." (I mean, it is not
a one-rule-applies behaviour for a module in its original and import-ed 
avatars.) Well, I might have still got it all mixed up!; so all comments
are welcome.

Thanks, 
Gangadhar.
[I am not fastidious about how I am being addressed; just wanted to tell
 you that you needn't address me formally and it can be done transparently
 if you wish to!]



More information about the Python-list mailing list