Python - 使用带连字符的游标中的列名

Python - Working with colun names in cursors with hyphens

当数据库列名称设计不当且其中包含连字符时,对 selecting 游标中的列的任何建议。我同意带有连字符的列名称是一个糟糕的设计,但这是 10 年前由其他人以这种方式设置的。这是一个示例,其中字段 time_offer_changed 工作正常但 sellker-sku 不工作。我可以 select 他们的原始位置 - row[6] 但我想为以后可能会接触此代码的人找到一些更容易理解的东西

cursor = db.cursor()  # prepare a cursor object using cursor() method
cursor.execute("SELECT * FROM tbl_inventory_data WHERE `ain`=%s AND `user`=%s", (AIN, SellerId)) 
db.commit()

for row in cursor.fetchall():
     r = reg(cursor, row)
     sku_time=r.time_offer_changed.  #works fne !!!!
     sku_seller_sku=r.seller-sku.    #no good !!!!!

要么将光标更改为 return 字典并通过 r['seller-sku'] 访问它,或者如果不是 possible/desirable 那么您始终可以使用 sku_seller_sku = getattr(r, 'seller-sku')