python3中bytes与string的互相转换
来源:互联网 发布:好玩的视频软件 编辑:程序博客网 时间:2024/05/23 11:33
首先来设置一个原始的字符串,
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/'>>>
0 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的互相转换
- 使用batch批处理做目录及流程选择
- c#中跨线程调用windows窗体控件
- 像职业选手样编码:地道Python
- 数据挖掘笔记 第一章:引言
- SVN使用教程(基于SAE)
- python3中bytes与string的互相转换
- python3实现域名查询和whois查询
- C#中的线程(一)入门
- C#中的线程(二)线程同步
- C#中的线程(三)多线程
- C#中的线程(四)高级话题
- C#中的BackgroundWorker控件
- C#中的MessageBox消息对话框
- Linux解压 tar命令