Python3中bytes与string的互相转换
来源:互联网 发布:读英语单词的软件 编辑:程序博客网 时间:2024/06/05 04:31
来源:python3中bytes与string的互相转换
首先来设置一个原始的字符串,
Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> website = 'http://www.cnblogs.com/txw1958/'>>> type(website)<class 'str'>>>> website'http://www.cnblogs.com/txw1958/'>>>
按utf-8的方式编码,转成bytes
>>> website_bytes_utf8 = website.encode(encoding="utf-8")>>> type(website_bytes_utf8)<class 'bytes'>>>> website_bytes_utf8b'http://www.cnblogs.com/txw1958/'>>>
按gb2312的方式编码,转成bytes
>>> website_bytes_gb2312 = website.encode(encoding="gb2312")>>> type(website_bytes_gb2312)<class 'bytes'>>>> website_bytes_gb2312b'http://www.cnblogs.com/txw1958/'>>>
解码成string,默认不填
>>> website_string = website_bytes_utf8.decode()>>> type(website_string)<class 'str'>>>> website_string'http://www.cnblogs.com/txw1958/'>>>>>>
解码成string,使用gb2312的方式
>>> website_string_gb2312 = website_bytes_gb2312.decode("gb2312")>>> type(website_string_gb2312)<class 'str'>>>> website_string_gb2312'http://www.cnblogs.com/txw1958/'>>>
1 0
- python3中bytes与string的互相转换
- python3中bytes与string的互相转换
- python3中bytes与string的互相转换
- Python3中bytes与string的互相转换
- Python3中bytes与string的互相转换
- python3中bytes和string之间的互相转换
- python3中bytes和string转换及各进制转换
- java 中string与bytes的转换总结
- Java中int与String类型的互相转换
- Html5中JSON对象与String的互相转换
- Python3中bytes和HexStr之间的转换
- Python3中bytes和HexStr之间的转换
- Python3中bytes和HexStr之间的转换
- python3中string和bytes转化
- python3中string和bytes转化
- securitystring与string的互相转换
- string与double的互相转换
- CString与char * ,string的互相转换
- 以一颗积极的心对待苦难,他才会给你磨砺!
- this-对象的默认引用
- VS插件应用 ---- VS10x Code Map v2
- Html学习笔记 --- html 中深入理解语义化
- 第二十二期 OpenWrt 原理和结构分析《路由器就是开发板》
- Python3中bytes与string的互相转换
- Leetcode-71. Simplify Path
- Hive 实践(四)、Hive 语法归纳
- 自定义viewgroup
- 串行通信接口小结
- 三层架构
- 使用Pageant Keyt创建key/value SSH Key
- JAVA中文编码和中文字符长度问题和解决方案
- HDU ACM 11 2012 素数判定