我正在尝试从文本文件tweet_file
中读取Twitter数据,然后获取tweet文本并将其附加到tweet_data
,然后打印该tweet文本。但是我在for t in tweet_data :
行说tweet_data not defined
时收到名称错误。这是我正在尝试的代码:
with open(tweet_file) as f :
for line in f:
response = json.loads(line)
print response["text"]
if "text" in response.keys():
tweet_data.append(response["text"])
print response["text"]
#print response.keys()
#print len(tweet_data)
# For each tweet:
for t in tweet_data:
total = 0
# Convert from <type 'unicode'> to <type 'str'>
encoded_t = t.encode('utf-8')
words = encoded_t.split()
# print (str(words))