Name space quirk?
NANDYALA D Gangadhar
n_d_gangadhar at yahoo.com
Sun Jul 22 14:19:34 CEST 2001
[Sorry if this is documented and I missed it; I am pretty new to python.]
Running the following as a script goes through (unexpectedly, for me),
while trying to run it in the interactive python shell catches the
NameError (on "myfile"):
from os import sys
def hello (outfile = sys.stdout):
# We are writing to what should be an
# unknown file descriptor:
myfile.write ("Hello, world!\n")
if __name__ == '__main__':
f = sys.argv + ".out"
myfile = open (f, 'w')
Is this behaviour desirable and correct? I guess it can lead to
As you expect, I saw this when I happened to change my variable name
only inside a function, and discovered it after using it a lot of times.
More information about the Python-list