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的更多相关文章

  1. python3的encode()和decode()

    python3的encode()和decode() 在python3的内存中. 在程序运行阶段. 使⽤用的是unicode编码. 因为unicode是万国码. 什么内容都可以进行显示. 那么在数据传输 ...

  2. python3 str或bytes转换函数

    str或bytes始终返回为str #!/usr/bin/env python # -*- coding: utf-8 -*- def to_str(bytes_or_str): if isinsta ...

  3. python3 str和bytes转换

    bytes object b = b"example" str object s = "example" #str to bytes bytes(s, enco ...

  4. python3 中encode 和decode的使用方法。

    编码: 将文本转换成字节流的过程.即Unicode----------->特定格式的编码方式,产生特定的字节流保存在硬盘中(一般为utf-8格式). 解码: 将硬盘中的字节流转换成文本的过程.即 ...

  5. python3 str和bytes之间转换

    a bytes-like object is required, not 'str' 碰到 这个错误 ,是因为需要是的bytes,不是str bytes -> str: 1  str-> ...

  6. Python中的str与bytes之间的转换的三种方法

    # bytes object b = b"example" # str object s = "example" # str to bytes sb = byt ...

  7. Python3 关于UnicodeDecodeError/UnicodeEncodeError: ‘gbk’ codec can’t decode/encode bytes类似的文本编码问题

    以下是小白的爬虫学习历程中遇到并解决的一些困难,希望写出来给后来人,如有疏漏恳请大牛指正,不胜感谢! 首先,我的代码是这样的 import requests url = 'http://www.acf ...

  8. python的str,unicode对象的encode和decode方法, Python中字符编码的总结和对比bytes和str

    python_2.x_unicode_to_str.py a = u"中文字符"; a.encode("GBK"); #打印: '\xd6\xd0\xce\xc ...

  9. python数据池,python3编码str转bytes,encode

    一.python2 python3的区别 默认编码:2--ASCII码  3---UTF-8 print:python2 可以不需要加括号(),python3必须加括号 python2中有range, ...

随机推荐

  1. js加密(十四)mail.yw.gov.cn/ RSA

    1. url: http://mail.yw.gov.cn/ 2. target:登录js 3. 简单分析: 寻找加密js: 3.1 直接寻找加密的参数p是不好找的,所以我们试着去寻找一些更明显的参数 ...

  2. Flink 容错机制与状态

    简介 Apache Flink提供了一种容错机制,可以持续恢复数据流应用程序的状态. 该机制确保即使出现故障,经过恢复,程序的状态也会回到以前的状态. Flink 主持 at least once 语 ...

  3. HZNU-ACM寒假集训Day12小结 数论入门 题解

    算不出的等式 BJOI2012 看到这题 真没什么办法 无奈看题解 1.注意到p/q 联想到斜率 2.注意到 [ ] 联想到整点 注意到k在变化,构造一次函数 f(x)=p/q*x ,g(x)=q/p ...

  4. 吴裕雄--天生自然C++语言学习笔记:C++ 信号处理

    信号是由操作系统传给进程的中断,会提早终止一个程序.在 UNIX.LINUX.Mac OS X 或 Windows 系统上,可以通过按 Ctrl+C 产生中断. 有些信号不能被程序捕获,但是下表所列信 ...

  5. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) E. Arson In Berland Forest

    E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every ce ...

  6. HDU 5455:Fang Fang 查cff个数

    Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  7. mnist数据集tensorflow实现

    TensorFlow——CNN实现MNIST手写体识别 2019年04月08日 21:46:19 星空Ice_ 阅读数 83   文章目录 TensorFlowCNN实现MNIST 1,数据集 2,回 ...

  8. java获取键盘事件

    转 <script type="text/javascript" language=JavaScript charset="UTF-8"> docu ...

  9. COGS 1489玩纸牌

    %%%http://blog.csdn.net/clover_hxy/article/details/53171234 #include<bits/stdc++.h> #define LL ...

  10. php和js的小区别

    1.今天看了下php的api感觉还可以,不是很难,可能没看到深入的地方, (1)和js很相似 目前感觉它和js的最大区别 js的  点  被替换成 -> function setCate($pa ...