long integers

Michael Janssen Janssen at rz.uni-frankfurt.de
Mon Apr 1 16:26:51 EST 2002


converting long integer to integer strips off the "L":
>>> int(3L)
>>> 3


Michael Hall wrote:

> 
> G'day:
> 
> I'm using Python 1.5.2 and am having trouble with long integers when I
> pull data out of a MySQL database using MySQLdb. When I retrieve a
> numeric value from a field with an `int' data type, the value has an `L'
> stuck on the end.
> 
> In one script, I worked around this by stripping the L off with:
> 
> var = numeric_id # ("2L")
> var = var[:-1]
> print var
>>> 2
> 
> In this case, numeric_id was passed through a hidden field in an HTML
> form. But this doesn't work in another script for some reason, where
> the value is passed straight from a database query. I tried
> converting the data type from number to string, but that doesn't work
> either:
> 
> var = result[0] # ("2L")
> var = 'var[:-1]'
> print var
>>> var[:-1]
[snip]




More information about the Python-list mailing list