OSError: [Errno 22] when I try to .read() a json file(OSError: [Errno 22] 当我尝试 .read() 一个 json 文件时)
问题描述
我只是想在 Python 中读取我的 json 文件.当我这样做时,我在正确的文件夹中;我在下载中,我的文件名为Books_5.json".但是,当我尝试使用 .read() 函数时,我得到了错误
I am simply trying to read my json file in Python. I am in the correct folder when I do so; I am in Downloads, and my file is called 'Books_5.json'. However, when I try to use the .read() function, I get the error
OSError: [Errno 22] Invalid argument
这是我的代码:
import json
config = json.loads(open('Books_5.json').read())
这也会引发同样的错误:
This also raises the same error:
books = open('Books_5.json').read()
如果有帮助,这是我的数据的一小部分:
If it helps, this is a small snippet of what my data looks like:
{"reviewerID": "A10000012B7CGYKOMPQ4L", "asin": "000100039X", "reviewerName": "Adam", "helpful": [0, 0], "reviewText": "Spiritually and mentally inspiring! A book that allows you to question your morals and will help you discover who you really are!", "overall": 5.0, "summary": "Wonderful!", "unixReviewTime": 1355616000, "reviewTime": "12 16, 2012"}
{"reviewerID": "A2S166WSCFIFP5", "asin": "000100039X", "reviewerName": "adead_poet@hotmail.com "adead_poet@hotmail.com"", "helpful": [0, 2], "reviewText": "This is one my must have books. It is a masterpiece of spirituality. I'll be the first to admit, its literary quality isn't much. It is rather simplistically written, but the message behind it is so powerful that you have to read it. It will take you to enlightenment.", "overall": 5.0, "summary": "close to god", "unixReviewTime": 1071100800, "reviewTime": "12 11, 2003"}
我在 MacOSX 上使用 Python 3.6
I'm using Python 3.6 on MacOSX
推荐答案
看来这是文件太大时出现的某种错误(我的文件是~10GB).一旦我使用 split
将文件分成 200 k 行,.read()
错误就会消失.即使文件不是严格的 json 格式也是如此.
It appears that this is some kind of bug that occurs when the file is too large (my file was ~10GB). Once I use split
to break up the file by 200 k lines, the .read()
error goes away. This is true even if the file is not in strict json format.
这篇关于OSError: [Errno 22] 当我尝试 .read() 一个 json 文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OSError: [Errno 22] 当我尝试 .read() 一个 json 文件时
基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01