因为是NoneType,所以无法对列表进行排序?简单的Python
发布于 2021-01-29 18:23:37
当我尝试为我的BeautifulSoup网络刮板找出低价和高价时,出现此错误。我附上了下面的代码。我的列表不应该是整数列表吗?
在发布此消息之前,我经历了类似的NoneType问题,但是解决方案不起作用(或者我听不懂!)
Traceback (most recent call last):
File "/home/user-machine/Desktop/cl_phones/main.py", line 47, in <module>
print "Low: $" + intprices[0]
TypeError: 'NoneType' object is not subscriptable
相关摘要:
intprices = []
newprices = prices[:]
total = 0
for k in newprices:
total += int(k)
intprices.append(int(k))
avg = total/len(newprices)
intprices = intprices.sort()
print "Average: $" + str(avg)
print "Low: $" + intprices[0]
print "High: $" + intprices[-1]
关注者
0
被浏览
46
1 个回答