使用Python,此代码中的"wb"是什么意思? [英] What does 'wb' mean in this code, using Python?
问题描述
代码:
file('pinax/media/a.jpg', 'wb')
推荐答案
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文件中的一样.
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屋!