python读取一个文件的大小有限制吗_read()的文件大小限制?

我在尝试使用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还是应该使用其他方法来读取文件?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值