码迷,mamicode.com
首页 > 编程语言 > 详细

python3 str.encode bytes.decode

时间:2017-08-30 11:51:37      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:rar   change   sig   3.1   unicode   tle   set   from   nic   

str.encode

把字符串编码成字节序列

 

bytes.decode

把字节序列解码成字符串

 

https://docs.python.org/3.5/library/stdtypes.html

 

str.encode(encoding=”utf-8”, errors=”strict”)

Return an encoded version of the string as a bytes object. Default encoding is ‘utf-8‘. errors may be given to set a different error handling scheme. The default for errors is ‘strict‘, meaning that encoding errors raise a UnicodeError. Other possible values are ‘ignore‘, ‘replace‘, ‘xmlcharrefreplace‘, ‘backslashreplace‘ and any other name registered via codecs.register_error(), see section Error Handlers. For a list of possible encodings, see section Standard Encodings.

Changed in version 3.1: Support for keyword arguments added.

 

bytes.decode(encoding=”utf-8”, errors=”strict”)
bytearray.decode(encoding=”utf-8”, errors=”strict”)

Return a string decoded from the given bytes. Default encoding is ‘utf-8‘. errors may be given to set a different error handling scheme. The default for errors is ‘strict‘, meaning that encoding errors raise a UnicodeError. Other possible values are ‘ignore‘, ‘replace‘ and any other name registered via codecs.register_error(), see section Error Handlers. For a list of possible encodings, see section Standard Encodings.

Note

Passing the encoding argument to str allows decoding any bytes-like object directly, without needing to make a temporary bytes or bytearray object.

Changed in version 3.1: Added support for keyword arguments.

 

 

python3 str.encode bytes.decode

标签:rar   change   sig   3.1   unicode   tle   set   from   nic   

原文地址:http://www.cnblogs.com/antflow/p/7452208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!