Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获得第一元素Peewee?_Python_Python 3.x_Peewee - Fatal编程技术网

Python 如何获得第一元素Peewee?

Python 如何获得第一元素Peewee?,python,python-3.x,peewee,Python,Python 3.x,Peewee,有一个问题: r = Products.select().where(Products.sku == article) 我试图得到第一个元素,如: print (oldRow.first()) 还尝试了:print(oldRow[0]) 我有一个错误: Error has occurred: Cannot convert b'7115.0000' to Decimal 我想这可能是你发布的同一个错误的例子(一个类似的问题)。请尝试此修补程序: 此外,Peewee模型实例不可下标。您应该使

有一个问题:

r = Products.select().where(Products.sku == article)
我试图得到第一个元素,如:

print (oldRow.first())
还尝试了:
print(oldRow[0])

我有一个错误:

Error has occurred: Cannot convert b'7115.0000' to Decimal

我想这可能是你发布的同一个错误的例子(一个类似的问题)。请尝试此修补程序:

此外,Peewee模型实例不可下标。您应该使用
oldRow.price
--而不是
oldRow[0]
访问元素。查询返回的对象是模型实例,除非您明确告诉peewee返回元组/dicts/namedtuples


我还尝试了以下操作:
返回产品。选择(Products.model)。其中(Products.sku==article)。get()
它返回我:
发生错误:“Products”对象不可订阅