我TypeError: cannot serialize ('John',) (type tuple)
在第一次迭代中得到了这段代码。为什么SELECT name FROM potluck
输出'John',
而不是输出'John'
?
('John',)
('Sandy',)
('Tom',)
('Tina',)
反正我不知道是不是这个问题。
#!/usr/bin/env python
import psycopg2
import sys
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
con = None
try:
con = psycopg2.connect(database='events', user='demo')
cur = con.cursor()
cur.execute("SELECT name FROM potluck")
rows = cur.fetchall()
top = Element('top')
for row in rows:
#print row
comment = Comment('Generated test')
top.append(comment)
child = SubElement(top, 'child')
child.text = row
print tostring(top)
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()