Overflow error when printing long values

Tim Peters tim.one at home.com
Fri Aug 31 03:26:51 EDT 2001


[Michael Teo]
> However, I noticed that Python 2.1 does not give a trailing 'L'
> for str(l).
> Is there any solution which will work well for Python 1.5.2 and
> Python 2.1 ?

    repr(somelong)[:-1]

or

    `somelong`[:-1]

or be straightforward instead of suicidally clever:

    def tostr(i):
        "Return integer i as string, without trailing 'L'."
        s = str(i)
        if s[-1] == 'L':
            s = s[:-1]
        return s

By being straightforward, you don't have to worry, e.g., about chopping off
the last digit of a short int "by mistake".





More information about the Python-list mailing list