simpli int/str problem

wittempj@hotmail.com martin.witte at gmail.com
Fri Aug 12 10:54:23 EDT 2005


Use substitution like below.
Hope this helps

py> d = {'str_name': 'etc' , 'int_name' : 112 }
py> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + d['str_name'] + "',
'" + d['int_name'] + "')"

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + d['str_name'] + "',
'" + d['int_name'] + "')"
TypeError: cannot concatenate 'str' and 'int' objects
py> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('%s', %d)" %
(d['str_name'], d['int_name'])
py> print SQL
INSERT INTO (`AH`, `BH` ) VALUES ('etc', 112)
py>




More information about the Python-list mailing list