long integers

Michael Hall olc at ninti.com
Sun Mar 31 07:08:12 EST 2002


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]

So now I'm confused. I don't yet know enough Python to know what to try
now. Is there some easy way around this problem? Can this be fixed in
MySQL by changing or modifying the data type, or should I upgrade to a
later version of Python?

Thanks

Mick

-----------------------------
Michael Hall   mick at ninti.com
-----------------------------





More information about the Python-list mailing list