Used to 'file = open(...)', now what?
John Hunter
jdhunter at ace.bsd.uchicago.edu
Wed May 7 16:46:36 EDT 2003
>>>>> "Grzegorz" == Grzegorz Adam Hankiewicz <gradha at titanium.sabren.com> writes:
Grzegorz> But with Python 2.2 file() is a builtin constructor,
Grzegorz> making open deprecated, possibly dropped in a future
Grzegorz> version. Now what would be the "usual" way to name file
Grzegorz> variables without hiding the constructor?
I sometimes use
fh = file('somefile.dat') # for file handle
or
fi = file('somefile.dat', 'r') # for file input
fo = file('somefile.dat', 'w') # for file output
or if you like longer names
inFile = file('somefile.dat', 'r')
outFile = file('somefile.dat', 'w')
Also, often you don't need to name it at all
for line in file('somefile.dat'):
print line
I don't think there is 'a preferred way'.
JDH
More information about the Python-list
mailing list