这个代码中使用Python的'wb'是什么意思? [英] What is the 'wb' mean in this code, using Python?

查看:421
本文介绍了这个代码中使用Python的'wb'是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

file('pinax/media/a.jpg', 'wb')


推荐答案

文件模式,写入和二进制。因为你正在写一个.jpg文件,看起来不错。

File mode, write and binary. Since you are writing a .jpg file, it looks fine.

但是,如果您要阅读该JPG文件,则需要使用'rb'

But if you supposed to read that jpg file you need to use 'rb'

更多信息


在Windows上,'b'附加到
模式下打开文件在二进制模式下,所以
还有'rb','wb',
和'r + b'的模式。 Windows上的Python在文本和二进制
文件之间产生
的区别;在读取或写入数据时,
文本文件中的行尾字符会自动更改

对于ASCII文本
文件,
文件数据的这个场景修改很好,但是会损坏像JPEG或EXE文件中的二进制数据
。 p>

On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'. Python on Windows makes a distinction between text and binary files; the end-of-line characters in text files are automatically altered slightly when data is read or written. This behind-the-scenes modification to file data is fine for ASCII text files, but it’ll corrupt binary data like that in JPEG or EXE files.

这篇关于这个代码中使用Python的'wb'是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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