gpt4 book ai didi

python - GET 趋势/地点的问题 (Twython)

转载 作者:行者123 更新时间:2023-11-28 16:42:39 26 4
gpt4 key购买 nike

尝试仅访问多伦多趋势的“名称”部分。到目前为止我有这个但是它给我错误:

toronto = t.get_place_trends(id=4118)

trend_array = []
for trend in toronto.trends.name:
trend_array.append(trend)
print trend_array
print trend

那是在 auth 之后返回强制放入数组(由于某种原因无法通过索引访问)的整个对象列表并作为列表返回。

最佳答案

哇,toronto 返回一个必须通过索引访问的列表,这真的很奇怪。

这是您需要的代码:

toronto = t.get_place_trends(id=4118)
trend_array = []

if toronto:
for trend in toronto[0].get('trends', []):
trend_array.append(trend['name'])
print trend_array
print trend

关于python - GET 趋势/地点的问题 (Twython),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com