enumerate overflow

Steve Holden steve at holdenweb.com
Wed Oct 3 16:17:03 CEST 2007

crwe at post.cz wrote:
> 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?
Just how "soon" exactly do you read sys.maxint lines from a file? I 
should have thought that it would take a significant amount of time to 
read 2,147,483,647 lines ...

But it is true that Python 2.5 uses an enumobject representation that 
limits the index to a (C) long:

typedef struct {
         long      en_index;    /* current index of enumeration */
         PyObject* en_sit;      /* secondary iterator of enumeration */
         PyObject* en_result;   /* result tuple  */
} enumobject;

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

More information about the Python-list mailing list