MySQLdb integer question
Polerio Babao Jr.II
admin at polerio.com
Mon Oct 20 01:34:11 EDT 2003
Ansgar Wollnik <wiseworld at web.de> wrote in message news:<bmung0$qbj7e$1 at ID-176487.news.uni-berlin.de>...
> Polerio Babao Jr.II wrote:
> >>I use Python with MySQLdb to transfer data from one database to another.
> >>When I SELECT the data from the first table, numbers are provided with
> >>an 'L' at the end to show, they are treated as a Long Integer (see:
> >>http://www.esrf.fr/computing/bliss/python2/MySQL/MySQLdb-3.html#ss3.4).
> >>
> >>Now I want to put that data into the new database but the 'L's are still
> >>there. What can I do?
>
> >>>>c = ('a',200L)
> >>>>print int(c[1])
>
> OK, that would work, if I would know what field contains an Integer or
> not...
>
> Could you help to determine weather a value is an Integer or not so I
> can to the needed INSERT INTO syntax?
>
> Ansgar
Use type() function to get the data type of your values.
>>> a = '23'
>>> b = 21L
>>> c = 22
>>> d = 23.45
>>> print type(a), type(b), type(c), type(d)
<type 'str'> <type 'long'> <type 'int'> <type 'float'>
>>> a = '23'
>>> b = type(a)
>>> c = '%s' % b
>>> if c[7:10]=='str':
... print 'This is a string!'
...
This is a string!
>>> a = '%s' % type(200.45)
>>> a
"<type 'float'>"
>>> a[7:11]
'floa'
>>> a[7:12]
'float'
>>> if a[7:12]=='float':
... print 'This is a float number!'
...
This is a float number!
>>>
Mabuhay!
More information about the Python-list
mailing list