confusion about opening files
Andrew Koenig
ark at research.att.com
Tue Sep 24 09:44:48 EDT 2002
Erik> Because there are two different open functions here. One is in the
Erik> builtins, one is in the os module. They are not the same:
In fact, the builtin "open" function is now called "file"; the name
"open" is there only for backward compatibility.
So the original example:
>>> import os
>>> file = os.open("e:\\d12", "r")
is bad news for two reasons:
1) It uses os.open when it should use the builtin function;
2) It uses a variable named "file", which will step on the
name of the builtin function.
If you write it this way:
# no need to import os here
myfile = file("e:\\d12", "r")
you may find the resulting code easier to understand.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list