Used to 'file = open(...)', now what?

Erik Max Francis max at alcyone.com
Thu May 8 20:03:57 EDT 2003


Grzegorz Adam Hankiewicz wrote:

> I'm very used to the following construct:
> 
>   file = open("whatever", flags)
>   buf = file.readlines()
>   file.close()
> 
> But with Python 2.2 file() is a builtin constructor, making open
> deprecated, possibly dropped in a future version. Now what would
> be the "usual" way to name file variables without hiding the
> constructor?

I have the same issue.  I just tend to give the file object name a more
descriptive name:

	inputFile = file(...)
	try:
	    ...
	finally:
	    inputFile.close()

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ An undevout astronomer is mad.
\__/ Edward Young
    Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/
 A personal guide to Aliens vs. Predator 2.




More information about the Python-list mailing list