Python' float' object不是可迭代的错误

时间:2017-04-29 13:55:20

标签: python api

错误讯息:

  

文件" C:/ Users / artisan / PycharmProjects / API connection / polo.py",line   12,在poloniexapi       total = sum([i(" quoteVolume"]中的num的[int(num)] TypeError:' float'对象不可迭代

{# In show.html #}
{% import "members:memberMacros.html" as memberMacros %}
{{ memberMacros.output(data.piece._members) }}  

{# in widget.html #}
{% import "members:memberMacros.html" as memberMacros %}
{{ memberMacros.output(data.widget._pieces) }}  

感谢所有帮助:)

1 个答案:

答案 0 :(得分:2)

for num in i['quoteVolume']正在尝试迭代i['quoteVolume']。但这只是一个数字(前一个for循环中的最后一个数字),而不是列表。我想你想要的是:

total = sum([int(i["quoteVolume"]) for i in json_obj])