On 11/10/13 16:23, Peter Otten wrote:
infile = open(name, 'r')
lst = infile.readlines()
infile.close()
You could do that in one line:
lst = open(name).readlines()
Talking about bad habits -- what you are suggesting here is a step in the
wrong direction.
with open(name) as infile:
lines = infile.readlines()
Good point, I should have used with.
(Slaps self on face with wet fish!)
for line in infile: ?
I actually considered this but decided it was one step too
far for the OP.
an intermediate Python user and know about generators you can try
to implement a generator like
I also considered a generator but decided that was way
too much for the OP! :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor