【发布时间】:2021-07-16 10:07:58
【问题描述】:
当我尝试从泡菜中打开某些部分时,我得到了这个错误
TypeError: 'bool' object is not subscriptable
filename = r"Biden_tweets.pkl"
full_text = []
with open(filename,"rb")as file:
while True:
try:
tweet = pickle.load(file)
full_text.append(tweet['retweeted']['full_text'])
#print(tweet.keys())
except EOFError:
break
这些是打印出来的键:
print(tweet.keys())
dict_keys(['created_at', 'id', 'id_str', 'full_text', 'truncated', 'display_text_range', 'entities', 'metadata', 'source', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'in_reply_to_screen_name', 'user', 'geo', 'coordinates', 'place', 'contributors', 'is_quote_status', 'retweet_count', 'favorite_count', 'favorited', 'retweeted', 'possibly_sensitive', 'lang'])
当我编辑我的代码时:
full_text.append(tweet['retweeted_status']['full_text'])
我得到:KeyError: 'retweeted_status'
但是当我打开时:
tweet['retweeted_status']['full_text']'
'Barr must be held accountable - and the Biden administration must release the fully unredacted Mueller report!
我得到输出
{'created_at': 'Mon Dec 14 23:56:27 +0000 2020',
'id': 1338633986067795970,
'id_str': '1338633986067795970',
'full_text': 'RT @Amy_Siskind: Barr must be held accountable - and the Biden administration must release the fully unredacted Mueller report!
'retweeted_status': {'created_at': 'Mon Dec 14 23:40:32 +0000 2020',
'id': 1338629978334826503,
'id_str': '1338629978334826503',
'full_text': 'Barr must be held accountable - and the Biden administration must release the fully unredacted Mueller report!'
【问题讨论】: