Question
Hi, I am trying to load tweets data, but some of the tweets are intentionally damaged and will not parse properly. You will need to
Hi, I am trying to load tweets data, but some of the tweets are intentionally damaged and will not parse properly. You will need to store these damaged tweets in a separate error file. For tweets that could not parse, write them into errors.txt file (do not ignore). My question is I don't know how to write them into txt file correctly. My syntax is as below:
import json for tweet in allTweets: try: tdict = json.loads(tweet.decode('utf8'))
..... except ValueError:
newtweet=tweet.decode('utf8') outfile=open("errors.txt","w")
outfile.write(newtweet)
outfile.close()
print (tweet)
in terms of the line: outfile.write(newtweet), I get the EncodeError message:'ascii' codec can't encode characters in position 467-468: ordinal not in range(128)
How to correct that? what's my problem?
Please ignore the incorrect indentation in my syntax, I don't know why I cannot edit the format. Thanks in advance!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started