TypeError:“bool”对象在NLP上不可下标

2024-09-30 01:25:53 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试着从pickle打开一些部件时,我得到了这个错误

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!'

Tags: thetotextinidstatuskeysreply

热门问题