如何获得第一个元素Peewee?
How to get first element Peewee?
有查询:
r = Products.select().where(Products.sku == article)
我试图获取第一个元素,例如:
print (oldRow.first())
也尝试过:print (oldRow[0])
我有一个错误:
Error has occurred: Cannot convert b'7115.0000' to Decimal
我认为这可能与您发布的相同错误(类似问题)有关。试试这个补丁:
https://github.com/coleifer/peewee/commit/cd07f4e01a1262166d8944736e11d0681fb76214
此外,Peewee 模型实例不可订阅。您应该使用 oldRow.price
而非 oldRow[0]
访问该元素。除非您明确告诉 peewee 到 return tuples/dicts/namedtuples.
,否则由查询编辑的对象 return 是模型实例
http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.tuples
有查询:
r = Products.select().where(Products.sku == article)
我试图获取第一个元素,例如:
print (oldRow.first())
也尝试过:print (oldRow[0])
我有一个错误:
Error has occurred: Cannot convert b'7115.0000' to Decimal
我认为这可能与您发布的相同错误(类似问题)有关。试试这个补丁:
https://github.com/coleifer/peewee/commit/cd07f4e01a1262166d8944736e11d0681fb76214
此外,Peewee 模型实例不可订阅。您应该使用 oldRow.price
而非 oldRow[0]
访问该元素。除非您明确告诉 peewee 到 return tuples/dicts/namedtuples.
http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.tuples