【问题标题】:FileNotFoundError: [Errno 2] No such file or directory. Yes the path exist, yes I'm using absolute pathFileNotFoundError: [Errno 2] 没有这样的文件或目录。是的,路径存在,是的,我使用的是绝对路径
【发布时间】:2021-08-15 22:14:26
【问题描述】:

我想将我的 json 文件拆分成多个部分。即使文件和路径存在,我仍然会遇到此错误

image of file path

import os
import json

with open(os.path.join(r'C:\Users\flipp\Downloads\decompressed', 'signalmedia-1m.json'), 'r',
          encoding='utf-8') as f1:
    ll = [json.loads(line.strip()) for line in f1.readlines()]

    
    print(len(ll))

   
    size_of_the_split=2000
    total = len(ll) // size_of_the_split

  
    print(total+1)

    for i in range(total+1):
        json.dump(ll[i * size_of_the_split:(i + 1) * size_of_the_split], open(
            r"C:\Users\flipp\Downloads\smaller files\usedData"+ str(i+1) + ".json", 'w',
            encoding='utf8'), ensure_ascii=False, indent=True)

【问题讨论】:

    标签: python compiler-errors


    【解决方案1】:

    从您发布的图片看来,该文件不是 json 文件,而是 zip 文件。

    要检查这一点,我认为您可以选择显示文件扩展名的选项,如 here. 所述

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 2022-01-15
      • 2018-12-16
      • 2021-01-12
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      相关资源
      最近更新 更多