python里面的代码是什么状态的,这个代码中使用Python的'wb'是什么意思?

本文介绍了Python中处理二进制文件的模式,如'wb'用于写入二进制文件,而'rb'用于读取。在Windows上,'b'标志用于区分文本和二进制文件,防止ASCII文本文件的换行符转换导致二进制数据(如JPEG或EXE文件)损坏。
摘要由CSDN通过智能技术生成

Code:

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

解决方案

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

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

More info

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值