Python 3:gzip.open()和模式 [英] Python 3: gzip.open() and modes

查看:353
本文介绍了Python 3:gzip.open()和模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://docs.python.org/3/library/gzip.html

我正在考虑使用gzip.open(),并且对mode参数有些困惑:

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

mode参数可以是'r','rb','a','ab','w','wb','x'中的任何一个 或对于二进制模式为'xb',对于文本模式为'rt','at','wt'或'xt'. 默认值为"rb".

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'.

那么'w''wb'有什么区别?

文档指出它们都是 binary模式.

那么这是否意味着'w''wb'之间没有区别?

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

推荐答案

这意味着r默认为rb,如果要输入文本,则必须使用rt进行指定.

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

(与open行为相反,其中r表示rt,而不是rb)

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

这篇关于Python 3:gzip.open()和模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆