Linked by pkrumins on Thu 19th Feb 2009 12:17 UTC
General Development If you have ever been interested in awk and sed Unix utilities, then you probably know about the awk1line.txt and sed1line.txt files that are floating around the Internet. Each file contains around 80 idiomatic sed and awk one-liners for performing various text modification tasks.
Thread beginning with comment 349861
To view parent comment, click here.
To read all comments associated with this story, please click here.
vivainio
Member since:
2008-12-26

How many lines do you have to write in python, just to open a file and read it?


One. cont = open("file.txt").read().

Or

for line open("file.txt"): do_stuff_with(line)

If that means significant extra work for you, you need a harder problem domain ;-)

Reply Parent Score: 3

RandomGuy Member since:
2006-07-30


for line open("file.txt"): do_stuff_with(line)

That should be:
for line in open("file.txt"): do_stuff_with(line)

If that means significant extra work for you, you need a harder problem domain

Agreed.

Reply Parent Score: 2

pkrumins Member since:
2008-05-07


for line open("file.txt"): do_stuff_with(line)

That should be:

for line in open("file.txt"): do_stuff_with(line)


It's neither. It should be:

<pre>
with file("file.txt") as fd:
for line in fd:
do_stuff_with(line)
</pre>

Edited 2009-02-20 23:27 UTC

Reply Parent Score: 1