【问题标题】:Error trying to decode json for reading tweepy tweets尝试解码 json 以读取 tweepy 推文时出错
【发布时间】:2022-01-15 20:07:48
【问题描述】:

我收到一个错误 ValueError: I/O operation on closed file。使用以下代码时,我的其余代码似乎工作正常,有什么想法吗?

tweets_file = open(tweets_data_path, 'r')

for line in tweets_file:
   tweet = json.loads(line)
   tweets_data.append(tweet)

    ValueError                                Traceback (most recent call last)
<ipython-input-44-722708c7e759> in <module>()
      1 # Read in tweets and store in list: tweets_data
----> 2 for line in tweets_file:
      3   tweet = json.loads(line)
      4   tweets_data.append(tweet)

ValueError: I/O operation on closed file.

【问题讨论】:

    标签: python tweepy jsondecoder


    【解决方案1】:

    要解决这个问题,您可以使用 with 关键字

    
    with open('filename.extention', 'r') as myfile:
        do you thing in here
    
    

    【讨论】:

      猜你喜欢
      • 2022-11-19
      • 2022-01-09
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 2015-09-04
      • 2015-04-27
      • 2013-01-01
      • 2018-11-08
      相关资源
      最近更新 更多