opening a file opens it in Notepad
Alex Martelli
aleax at aleax.it
Thu Feb 6 04:01:41 EST 2003
Lance wrote:
> Hi All,
>
> I'm running PythonWin build 148 on Windows XP.
>
> The following results in the file being opened in Notepad! This confuses
> me greatly. I simply want the file handle. My next line is to read the
> file into a string, using f1.read()
> Any suggestions will be appreciated.
You may have a
from whoknows import *
somewhere which is trampling the built-in name 'open' (or less
likely some other way to rebind that built-in name).
Forget about the existence of the 'from' statement and always
use 'import' -- a rather extreme suggestion, but I think that
for most people following it would enhance their code quality.
> Also, I have a number of files in srcfiles. I imagine I must issue
> f1.close() each time in the loop, yes?
It's cleaner style, though in current CPython it's not strictly
necessary (but it *IS* in Jython and may become so in some future
CPython, and it's a very good thing to get into the habit of so
doing: "explicit is better than implicit").
Alex
More information about the Python-list
mailing list