Overflow error when printing long values

Tim Peters tim.one at home.com
Fri Aug 31 02:12:57 EDT 2001


[Michael Teo]
> I get an "OverflowError: long int too long to convert" when I tried to
> print "%d" % l where l is a long Python value.

That was true in older versions of Python, but not anymore.

> I have tried using str(l) but that gives a trailing 'L'.

Also true, but in versions even older than that <wink>.

> Any good suggestion on how to solve this problem will be greatly
> appreciated. Thanks.

Works without effort in 2.1.1 (the latest stable release).  If you want
something that works under all Python releases (to date ...), print

    repr(l)[:-1]  # chops off trailing 'L'





More information about the Python-list mailing list