以下を使用して、ライブ Twitter ツイートにアクセスする Python スクリプトの出力をファイル output.txt にパイプしました。
$python scriptTweet.py > output.txt
もともと、スクリプトによって返された出力は、テキスト ファイルに書き込まれた辞書でした。
ここで、output.txt ファイルを使用して、そこに保存されているツイートにアクセスしたいと考えています。しかし、このコードを使用して、json.loads() を使用して output.txt のテキストを python 辞書に解析すると:
tweetfile = open("output.txt")
pyresponse = json.loads('tweetfile.read()')
print type(pyresponse)
次のエラーが表示されます。
pyresponse = json.loads('tweetfile.read()')
File "C:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
ファイル output.txt の内容を再び辞書に変換するにはどうすればよいですか?