line number var like perl's $.?

Miki Tebeka mikit at zoran.co.il
Mon Nov 17 22:23:18 CET 2003


Hello Matthew,

> linenum = 0
> for line in open('blah.txt'):
>     linenum += 1
>     print linenum, ". ", line
In 2.3 you can use "enumerate"
for lnum, line in enumerate(open("blah.txt")):
    print lnum, ".", line

HTH.
Miki




More information about the Python-list mailing list