我在尝试使用Python3.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 "", line 1, in
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 "", line 1, in
OSError: [Errno 22] Invalid argument
我还注意到,在python2.7中不会发生这种情况。下面是在Python 2.7中运行的相同代码:
^{pr2}$
我正在使用OS X El Capitan 10.11.1。在
这是一个bug还是应该使用其他方法来读取文件?在