2013-09-30 83 views
0

我在第一次迭代中使用此代码获得TypeError: cannot serialize ('John',) (type tuple)。为什么SELECT name FROM potluck输出'John',而不是'John'TypeError:无法序列化 - 类型元组

('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() 
+0

您会在哪一行发生错误? –

回答

相关问题