当我试图找出我的 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]