[Tutor] Need to convert 1,987,087,234,456 to an int

Dick Moores rdm at rcblue.com
Thu Aug 16 04:31:37 CEST 2007


At 06:58 PM 8/15/2007, John Fouhy wrote:
>On 16/08/07, Dick Moores <rdm at rcblue.com> wrote:
> > Python sees 1,987,077,234,456 as a tuple:
> >  >>>type(1,987,077,234,456)
> > <type 'tuple'>
>
>Hmm, not for me:
>
> >>> type(1,987,077,234,456)
>Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>TypeError: type() takes 1 or 3 arguments

Tried again just now, and I got what you got. However:

 >>>m = 1,987,077,234,456
 >>>type(m) == tuple
True


>What python are you using? (2.5.1 for me)

XP, Python 2.5, editor is Ulipad


> > I need to convert things such as 1,987,077,234,456 to ints.
>
>You could do this:
>
> >>> def decomma(*t):
>...  return int(''.join(str(i) for i in t))
>...
>
>Thus:
>
> >>> decomma(1,234,567)
>1234567

That's cool! However, it doesn't solve the problem in my original post.

 >>> t = 1,987,087,234,456
   File "<input>", line 1
     t = 1,987,087,234,456
                 ^
SyntaxError: invalid token

 >>> def decomma(*t):
           return int(''.join(str(i) for i in t))

 >>> decomma(1,987,087,234,456)
   File "<input>", line 1
     decomma(1,987,087,234,456)
                     ^
SyntaxError: invalid token

Dick




More information about the Tutor mailing list