[Tutor] Need to convert 1,987,087,234,456 to an int
John Fouhy
john at fouhy.net
Thu Aug 16 03:58:06 CEST 2007
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
What python are you using? (2.5.1 for me)
> 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
Of course, if you have:
>>> n = 1,234,567
Then you can't do this:
>>> decomma(n)
Instead, do this:
>>> decomma(*n)
1234567
--
John.
More information about the Tutor
mailing list