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. 文本编辑器vim/vi——末行模式

    指令格式: #vim 文件路径作用:打开指定的文件. 进入方式:由命令模式进入,按下“:”或者“/(表示查找)”即可进入 退出方式: a. 按下esc b. 连按2次esc键 c. 删除末行全部输入字 ...

  2. ES6与ES5的继承

    ES6 ES6中的类 类与ES5中的构造函数写法类似 区别在于属性要放入constructor中,静态方法和属性实列不会继承 <script> class Person{ height=& ...

  3. Docker部署Python应用程序

    Docker部署Python应用程序 1. 单个py文件部署 生成Dockerfile 文件 插件用的豆瓣的镜像,,重置时间(容器的默认时间是UTC时间与宿主机的相差8小时). 文中需要三个插件(pe ...

  4. 课程作业02-1-课后作业1-(1)使用组合数公式利用n!来计算

    1.设计思想:运用递归阶乘的函数,依次求出n!.k!.(n-k)!,再根据组合数的公式计算(n!/(k!*(n-k)!)). 2.程序流程图: 3.源程序代码: //信1605-3 20163429 ...

  5. springMvc接收json和返回json对象

    导入三个包 页面: function sendJson(){ //请求json响应json $.ajax({ type:"post", url: "${pageConte ...

  6. int *const 与const int *问题

    自己一直就不太清楚int *const与const int*之间的差别,总是弄混,今天势必拿一个程序验证一下. 一个指针是有两个属性的,一个是它指向的地方,一个是它指向地方上的内容.两者的差别也在此. ...

  7. iPhone系统固若金汤,为何还有人偷苹果手机去卖?

    2016年初,美国FBI希望苹果开发软件用以解锁一部嫌疑人的iPhone.苹果虽然帮助FBI从疑犯iCloud账户中提取数据,但有些数据仍然不可获取.由于不知道手机密码,FBI也无法打开手机.虽然在最 ...

  8. 8 —— node —— 响应一切 html 需要的静态资源

      fs.readFile('.'+urls, function (err, data) {   res.end(data)   });

  9. 利用kindlegen实现txt格式小说转换为mobi格式小说(C++实现)

    一直以来喜欢在kindle上看小说,kindle不伤眼,也可以帮助控制玩手机的时间.但在kindle上看txt格式的网络小说就很头疼了,这类小说在kindle上是没有目录的,而且篇幅巨长.所以一直以来 ...

  10. window10 家庭版安装docker和php开发环境

    前期工作   一.在宿主机创建文件夹 D:\wnmp\mysql57-conf D:\wnmp\mysql57-log D:\wnmp\nginx110-conf D:\wnmp\nginx110-l ...