Re:First Impressions of Python from a Java Developer
by Luyt on Monday November 08, 2010 @04:22PM
(#1884066)
...and if you're processing text files line by line, it isn't even necessary to call read() or readlines() on the file, since a file object supports iteration. You could say:
[ Parent
| on HN ]
Re:First Impressions of Python from a Java Developer
by rbanffy on Monday November 08, 2010 @05:44PM
(#1884368)
You could also
[ do_something_to(line) for line in open('todo.txt') ]
Re:First Impressions of Python from a Java Developer
by xiongchiamiov on Monday November 08, 2010 @06:52PM
(#1884578)
Although you'd probably want to replace those square brackets with parens to make it a generator, if you're dealing with a largish file.