0
私はPythonでプログラムを書いています。これはTwitterのAPIを使用しています。私たちが望むトピックのつぶやきのリストをtwitterで探していて、それぞれのツイートを分析して、それは感情です。 私はループのためにcmdのつぶやきを表示するのに使いました。プログラム内のループの最初のコードは Twitterの感情分析CSV io.unsupportedOperationエラー
api = tweepy.API(auth)
public_tweets = api.search("Estonia")
for tweet in public_tweets:
print(tweet.text.encode("utf-8"))
analysis = TextBlob(tweet.text)
print(analysis.sentiment)
は今、私はcsvファイルを使用してテキストファイルに直接書き込みを作りたかったが、エラーが コード発生します
api = tweepy.API(auth)
public_tweets = api.search("Estonia")
with open("sentiment.txt") as scoreFile:
scoreFileWriter = csv.writer(scoreFile)
for tweet in public_tweets:
text = tweet.text
analysis = TextBlob(tweet.text)
sentiment = analysis.sentiment.polarity
scoreFileWriter.writerow([text, sentiment])
エラーを
C:\Users\ArturErik\Desktop>python sentiment.py
Traceback (most recent call last):
File "sentiment.py", line 23, in <module>
scoreFileWriter.writerow([text, sentiment])
io.UnsupportedOperation: not writable
私はPythonには新しく、このバグを修正することはできません。
を使用しようとしています。ファイルは存在しますか? Pythonはファイルへの書き込みアクセス権を持っていますか?エラーの様子から、ファイルが書き込み可能であるかのようには見えません。今後、問題を解決するために取った手順を含めてください。この場合、ファイルを書き込み可能にしようとしましたか? – garrettmurray