Nov-02-2018, 12:52 PM
Well, you've already got the loop:
for line in f: line = line.strip()To print, just add the print to it:
for line in f: line = line.strip() f_out.write('{}'.format(line))If you want the line numbers, and you want to stop at 10, you should add enumerate to the loop. Enumerate takes something you would loop over, and loops of the indexes of that thing and that thing (as a tuple).
for line_index, line in enumerate(f): line = line.strip() if line_index < 10: f_out.write('{} {}'.format(line_index + 1, line))I put the +1 in the last line because enumerate starts at 0, like Python indexes do.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures