I'm trying to insert an interger, a string and a list as a single record into a database, but am striking an error.
Here is my code:
values=nprnd.randint(10, size=48) #NUMPY ARRAY
valuelist= map(None, values); #Convert to list
guid=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(20)) #Generate guid
for x in range(4):
var_string = ', '.join('?' * 48)
valuelist.insert(0,x)
valuelist.insert(0,ent_guid)
#50 coloums in table, guid, x and 48 randomly generated values
query_string = 'INSERT INTO schema1 VALUES (%s,%d,%s);' % (guid, x, var_string)
cursor.execute(query_string, valuelist)
I keep getting an error saying:
Traceback (most recent call last):
File "script.py", line 19, in <module>
cursor.execute(query_string, valuelist)
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/MySQLdb/cursors.py", line 184, in execute
query = query % db.literal(args)
I know the cause of this error (Even SO has a few questions on the same error), but none of the solutions I've tried have solved this error for me
Any help would be appreciated
from uuid import uuid4; guid = uuid4().hex