[英]Convert a pyodbc.Row to a string
我需要将pyodbc.Row转换为字符串。 互联网提供了一些建议,但这些建议似乎都不适合我。
row = cursor.fetchone()
#unicodedata.normalize('NFKD', row).encode('ascii','ignore') #TypeError: must be unicode, not pyodbc.Row
#row.fieldname.encode('utf8') #AttributeError: 'pyodbc.Row' object has no attribute 'fieldname'
tblName = str(row)
tblName.replace("text:u","").replace("'","")
tblName = tblName.encode('utf-8')
print tblName
上面的代码给出了错误(以注释显示),或者似乎没有效果,如此处的输出所示:
(u'myTableName', ) # print tblName
SQL是
tablesWithId = "select table_name \
from INFORMATION_SCHEMA.COLUMNS \
where COLUMN_NAME like 'MyId' "
cursor.execute(tablesWithId)
Python 2.7
给定你的sql,我想你只想要:
row.table_name
“ table_name
”是您选择的列的名称,pyodbc使每一列成为行对象的方便属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.