python gzip.open,Python 3:gzip.open()和模式

本文解析了gzip.open()函数中'w'和'wb'模式的区别,尽管两者都支持二进制模式,但默认情况下'r'对应于'rb'。'w'用于创建新文件或覆盖现有文件,而'wb'则同时保持文本模式并确保二进制数据的正确写入。理解这俩的区别有助于避免文件模式混淆。
摘要由CSDN通过智能技术生成

I am considering to use gzip.open(), and I am a little confused about the mode argument:

The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x'

or 'xb' for binary mode, or 'rt', 'at', 'wt', or 'xt' for text mode.

The default is 'rb'.

So what is the difference between 'w' and 'wb'?

The document states they are both binary mode.

So does that mean that there is no difference between 'w' and 'wb'?

解决方案

It means that r defaults to rb, and if you want text you have to specify it using rt.

(as opposed to open behaviour where r means rt, not rb)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值