python读文件一行行读直到结束_python 读文本,读到389行后就自动结束,并没有将文本完整的读完,为啥会出现这个情况?...

展开全部

f = open ("7.txt",'r')

w = open ("11.txt",'a+')

while 1:

line = f.readline()

w.write(line)

print line

if not line:

break

如果你仔细阅读过官方文档的话, 你会发现open的定义open(file, mode=’r’, buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size in bytes of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

buffering参数是一个整数用来设置缓冲e5a48de588b63231313335323631343130323136353331333363393035策略, 0 - 关闭缓冲(仅适用于二进制模式), 1 - 行缓冲(仅适用于文本模式), 如果整数大于1, 将按照整数的大小设置块缓冲区大小

默认的-1代表由系统处理

Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

“Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值