enumerate overflow

Diez B. Roggisch deets at nospam.web.de
Wed Oct 3 08:03:46 EDT 2007


crwe at post.cz schrieb:
> Hello all,
> 
> in python2.4, i read lines from a file with
> 
> for lineNum, line in enumerate(f): ...
> 
> However, lineNum soon overflows and starts counting backwards. How do
> i force enumerate to return long integer?

Most probably you can't, because it is a C-written function I presume.

But as python 2.4 has generators, it's ease to create an enumerate yourself:


def lenumerate(f):
     i = 0
     for line in f:
         yield i, line
         i += 1

Diez



More information about the Python-list mailing list