readlines() question

Moshe Zadka moshez at math.huji.ac.il
Sat Jun 10 01:40:31 EDT 2000


On 9 Jun 2000, Aahz Maruch wrote:

> In article <Pine.GSO.4.10.10006092339580.29560-100000 at sundial>,
> Moshe Zadka  <moshez at math.huji.ac.il> wrote:
> >
> >Ummmmm...I'm known as a professional paranoid in many places, so I usually
> >code like:
> >
> >my_file = open("blah")
> >try:
> >	...my_file.read, my_file.readlines, etc.
> >finally:
> >	my_file.close()
> 
> And if you're *really* paranoid ;-)
> 
> try:
> 	my_file = open("blah")
> 	...my_file.read, my_file.readlines, etc.
> finally:
> 	my_file.close()

Not really. If 
my_file = open("blah")

fails there's

a) no need to close my_file
b) my_file has not been assigned yet

--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list