Strange MySQL Problem...

Victor Subervi victorsubervi at gmail.com
Wed Apr 2 15:36:43 EDT 2008


Hi;
I have this code which works fine:

#!/usr/local/bin/python
import _mysql
import MySQLdb, cPickle
host = 'mysqldb2.ehost-services.com'
user = 'user'
passwd = 'pass'
db = 'bre'
print 'Content-Type: image/jpeg\r\n'
print '<html><body>\nHi!\n'
connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
imgfile=open("1.jpg",'rb')
f = imgfile.read()
cursor = connection.cursor()
cursor.execute("CREATE TABLE justatest (name TEXT, ablob BLOB)")
names = 'aramis', 'athos', 'porthos'
data = {}
for name in names:
  datum = list(name)
  datum.sort()
  data[name] = cPickle.dumps(datum, 1)
sql = "INSERT INTO justatest VALUES (%s, %s)"
cursor.execute(sql, ('ramis', _mysql.escape_string(f)) )
imgfile.close()
connection.close()
print '\nBye!\n</body></html>'
Now, if I take out this part, which I can´t see does anything at all in the
code, it no longer works:

names = 'aramis', 'athos', 'porthos'
data = {}
for name in names:
  datum = list(name)
  datum.sort()
  data[name] = cPickle.dumps(datum, 1)
Why?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080402/adfa0c0a/attachment.html>


More information about the Python-list mailing list