file2lines
Delaney, Timothy
tdelaney at avaya.com
Tue Aug 1 20:28:53 EDT 2000
> I always write directly:
>
> for line in open('myfile').readlines():
> some_interesting_function(line)
>
> You can bury this within a `try...except' clause, of course,
> but I think
> better to not blindly hide all errors, in general. If you
Rather than hiding all errors blindly ...
file = None
try:
file = open('myfile')
for line in file.readlines():
some_interesting_function(line)
finally:
if file:
file.close()
It's definitely more verbose, but it will work in any Python implementation.
Tim Delaney
More information about the Python-list
mailing list