an enumerate question
Paulo da Silva
psdasilvaX at esotericaX.ptX
Tue Mar 20 13:09:47 EDT 2007
eight02645999 at yahoo.com escreveu:
> hi
> say i want to enumerate lines of a file
> eg
> for n,l in enumerate(open("file")):
> # print next line ie
>
> is there a way to print out the next line from current line using the
> above?.
> Or do i have to do a readlines() first to get it into a list eg
> d = open("file").readlines()
> for n, l in enumerate(d):
> print d[n+1]
>
> thanks
>
for n,l in enumerate(file("file")):
print n,l[:-1] # the :-1 is to drop the \n - print n,l, also works (end
with ',').
HTH
Paulo
More information about the Python-list
mailing list