Python PyODBC可以';t使用SQL Server Localdb引用列名

Python PyODBC可以';t使用SQL Server Localdb引用列名,python,sql-server,localdb,Python,Sql Server,Localdb,这里没有人。我正在针对sql server本地数据库编写脚本,无法基于列名调用值 cnxn = pypyodbc.connect('Driver={SQL Server Native Client 11.0};Server=(localdb)\database;integrated security = true') cursor = cnxn.cursor() cursor.execute("SELECT username FROM [students].[dbo].[users]") row

这里没有人。我正在针对sql server本地数据库编写脚本,无法基于列名调用值

cnxn = pypyodbc.connect('Driver={SQL Server Native Client 11.0};Server=(localdb)\database;integrated security = true')
cursor = cnxn.cursor()
cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
for row in rows:
    print (row.username)
cnxn.close()
返回AttributeError:“行”对象没有属性“用户名”

print (row) 
按预期转储数据。并将代码修改为:

cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
x=0
for row in rows:
    print (row.cursor_description[x][0])
cnxn.close()
返回每个记录的用户名

为什么我不能调用row.username?

使用
打印(row[“username”])

不支持列属性,仅支持通过索引或其标题名获取的列集合


pyodbc使用
行。属性
语法,pyodbc使用
行[“属性”]
语法。

pyodbc使用小写字母作为属性名称