小编cal*_*co_的帖子

read()的文件大小限制?

我在尝试使用Python 3.5加载大文件时遇到了问题.read()没有参数的使用有时会给出一个OSError: Invalid argument.然后我尝试只阅读部分文件,它似乎工作正常.我已经确定它在某处开始失败2.2GB,下面是示例代码:

>>> sys.version
'3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> x = open('/Users/username/Desktop/large.txt', 'r').read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
>>> x = open('/Users/username/Desktop/large.txt', 'r').read(int(2.1*10**9))
>>> x = open('/Users/username/Desktop/large.txt', 'r').read(int(2.2*10**9))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
Run Code Online (Sandbox Code Playgroud)

我也注意到在Python 2.7中不会发生这种情况.这是在Python 2.7中运行的相同代码:

>>> sys.version
'2.7.10 (default, …
Run Code Online (Sandbox Code Playgroud)

python macos file python-2.7 python-3.x

11
推荐指数
1
解决办法
3474
查看次数

标签 统计

file ×1

macos ×1

python ×1

python-2.7 ×1

python-3.x ×1