我需要将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)
Python2.7
考虑到你的sql,我想你只是想:
“
table_name
”是您选择的列的名称,pyodbc使每一列成为row对象的方便属性。相关问题 更多 >
编程相关推荐