line number var like perl's $.?

SBrunning at trisystems.co.uk SBrunning at trisystems.co.uk
Mon Nov 17 10:57:21 EST 2003


> From:	Matthew Wilson [SMTP:mwilson at sarcastic-horse.com]
> Is there an equivalent construct in python?  Or are people doing
> something like this:
> 
> linenum = 0
> for line in open('blah.txt'):
>     linenum += 1
>     print linenum, ". ", line
>   
for linenum, line in enumerate(file('blah.txt')):
    print linenum, line

You'll need Python 2.3 for this, mind.

Cheers,
Simon Brunning,
http://www.brunningonline.net/simon/blog/
--LongSig





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.





More information about the Python-list mailing list