python字符串编码和转换
来源:互联网 发布:gre作文字数 知乎 编辑:程序博客网 时间:2024/05/01 02:23
1. python内部以unicode编码存储字符串(和java类似),非unicdoe编码间转换需要经过unicode作为中间媒介
2. 如果字符串本身就是unicode,那么直接encode进行转换;如果字符串是utf-8,那么先转换为unicode(即decode过程),然后在转换为gb2312(即encode过程)
#!/usr/bin/env python#coding=utf-8s="中文"if isinstance(s, unicode):#s=u"中文" print s.encode('gb2312')else:#s="中文" print s.decode('utf-8').encode('gb2312')
3. python中的编码转换大底就是这三种编码:utf-8,unicode,gb2312
unicode -> utf-8 (or gb2312),直接encode
utf-8 (or gb2312) -> unicode ,直接decode
utf-8 -> gb2312(或gb2312 -> utf-8),先decode,再encode
0 0
- python字符串编码和转换
- Python中的字符串与字符编码:编码和转换问题
- Python中的字符串与字符编码:编码和转换问题
- python 字符串和编码
- python字符串和编码
- Python 字符串和编码
- Python 字符串和编码
- Python 字符串和编码
- Python字符串和编码
- Python字符串和编码
- python 字符串和编码
- python字符串和编码
- [转]Python字符串的编码转换、存储
- python字符串与url编码的转换
- Python中unicode编码的字符串和其他格式的字符串之间进行转换
- Python 字符串和编码问题
- Python基础教程-字符串和编码
- python的字符串和编码
- 欢迎使用CSDN-markdown编辑器
- 微信支付获取prepay_id以及回调地址
- 我国人口预计 15 年内是会逐渐分散在大中小城市,还是继续向大城市集中?我们应留在大城市发展吗?
- 创业那些年,我们一起走过的坑
- myeclipse安装svn,注销svn账号
- python字符串编码和转换
- 【jzoj4710】【Value】
- Java软件工程师就业思维图(2016年版)
- Android-运行时配置变更
- CountDownTimer
- 位图_纪中3076_bfs
- js 操作cookie
- Install Notepadqq in other Linux distros
- memcache