"Daniel Nogradi" <[EMAIL PROTECTED]> writes:

> A very simple question: I currently use a cumbersome-looking way of
> getting the first, second, etc. line of a text file:
> 
> for i, line in enumerate( open( textfile ) ):
>     if i == 0:
>         print 'First line is: ' + line
>     elif i == 1:
>         print 'Second line is: ' + line
>     .......
>     .......

from itertools import islice
first_five_lines = list(islice(open(textfile), 5))

print 'first line is', first_five_lines[0]
print 'second line is', first_five_lines[1]
...
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to