opening a file opens it in Notepad

Peter Hansen peter at engcorp.com
Thu Feb 6 08:40:10 EST 2003


Anton Muhin wrote:
> 
> Lance wrote:
> > for file in srcfiles:
> >         f1 = open(file,"r")
> >         ... do stuff...
> 
> Copy-paste of your code revealed no problem, pelase send the full
> script. BTW, using file as a variable is really, really bad --- file is
> a built-in function. 

Well, there's no need to be that extreme about it.  One might 
say using "file" as a name is "poor style", or perhaps merely "a bad
habit", but it's not likely (I think) to do anything more than
create a local variable which hides the global name "file", and
that local variable is of course not going to pollute the namespace
of any other code which relies on the builtin "file" binding.

I suspect there is lots and lots of code out there that innocently
uses variables named "input" or maybe "map", "hash", or "id" and
I doubt that many problems result.

But you're right that it is probably a good thing to learn to avoid...

-Peter




More information about the Python-list mailing list