unexplainable python

Mel mwilson at the-wire.com
Sun Sep 27 05:41:55 CEST 2009

dads wrote:

> When creating a script that converts digits to words I've come across
> some unexplainable python. The script works fine until I use a 5 digit
> number and get a 'IndexError: string index out of range'. After
> looking into it and adding some print calls, it looks like a variable
> changes for no reason. The example beneath is using the digits 34567,
> the _5digit function slices 34 off and passes it to the _2digit
> function, which works with 2 digit strings but the IndexError is
> raised. Please accept my apologies for the explanation, I'm finding it
> hard to put into words. Has anyone any idea why it's acting the way it
> is?

Yeah.  You convert a 5 digit number by calling _2digit for the thousands, 
and _4digit for the rest.  Why?


More information about the Python-list mailing list