python - 尝试从 Status 对象返回字段值时出错
问题描述
我有以下代码:
tweet = random.choice(result)
pprint(tweet)
tweet_id = tweet['id']
第一行正在工作,因为 pprint(tweet) 正在打印:
Status(ID=1228151646292762624, ScreenName=None, Created=Fri Feb 14 02:59:05 +0000 2020, Text='one person followed me // automatically checked by [REDACTED])
到控制台。问题出在 tweet_id = tweet['id'] 中。它给了我错误:
Task hello.tasks.my_task[13181b70-70a0-44cc-94d7-87f173fbe3cb] raised unexpected: TypeError("'Status' object is not subscriptable",)
显然状态对象的功能不像字典。那么如何从中获取字段“ID”呢?
解决方案
推荐阅读
- c - 为什么我的代码中的 fork() 函数没有创建子进程?
- android - Chrome 自定义选项卡自定义(如 setToolbarColor、开始和退出动画)不起作用
- c# - 如何反序列化和显示这些实例
- sap - 如何在事实表中使用表的主键?[电源设计师]
- amazon-web-services - AWS Elastic-Beanstalk:ECS 任务因以下原因停止:任务无法启动。(nginx-proxy: php-app: )
- mysql - 升级到mysql8后mysqldump慢
- javascript - 用点读取目录中的文件
- ssh - ssh:连接到主机 github.com 端口 22:仅在单个项目上
- python - Twitter Search API 使用正则表达式过滤推文:“没有找到推文”
- azure - 对于 Azure Cosmos DB,是否可以从单区域写入更改为多区域写入?