python peewee 查询,以列名作为变量

python peewee query, with column name as variable

Peewee查询如下:

q = AccountTab.get(AccountTab.id == 12345)
print(q.name)

如果这里的 name 存储在一个变量中,比如 user_name 会怎样?有这样的吗?

q = AccountTab.get(AccountTab.id == 12345)
print(q.#{user_name})

感谢您的宝贵时间!

getattr 有效:

user_name = 'name'
print(getattr(q, user_name))