unicode .decode /str.encode方法
来源:互联网 发布:淘宝买家退货调包衣服 编辑:程序博客网 时间:2024/05/16 19:51
根据前面很多位大侠的邮件,我列了下面的表,只是还缺少一些说明,请知情者告知:
下面是一些编码转换用到的方法,请问, 下表中的 (3) 和 (5) ,即str.encode 和 unicode.decode 方法是做什么用的? 能否给出例子?
(1) unicode()
全局函数,将str字符串从其它编码(如gb2312)转换为unicode对象
(2) str.decode()
(2) str.decode()
str字符串的方法,将str字符串从其它编码(如gb2312)转换为unicode对象,与unicode()很相似.
(3) str.encode()
(3) str.encode()
str字符串的方法,
(4) unicode.encode()
(4) unicode.encode()
unicode对象的方法,将unicode对象转成其它相应编码的str字符串对象,如gb2312.
(5) unicode.decode()
(5) unicode.decode()
unicode对象的方法
我在此给出条目 (1), (2), (4) 方法的应用例子, 请大家补充(3),(5)的应用例子.
例子:
>>> s="中文" #str对象
>>> ss=u"中文" #unicode对象
>>> type(s)
<type 'str'>
>>> type(ss)
<type 'unicode'>
>>> s1=unicode(s,'mbcs') # str对象 --> unicode对象
>>> s1
u'/u4e2d/u6587'
>>> type(s1)
<type 'unicode'>
>>> s3=ss.encode('mbcs') # unicode对象 --> str对象
>>> s3
'/xd6/xd0/xce/xc4'
>>> type(s3)
<type 'str'>
>>> s="中文" #str对象
>>> ss=u"中文" #unicode对象
>>> type(s)
<type 'str'>
>>> type(ss)
<type 'unicode'>
>>> s1=unicode(s,'mbcs') # str对象 --> unicode对象
>>> s1
u'/u4e2d/u6587'
>>> type(s1)
<type 'unicode'>
>>> s3=ss.encode('mbcs') # unicode对象 --> str对象
>>> s3
'/xd6/xd0/xce/xc4'
>>> type(s3)
<type 'str'>
- unicode .decode /str.encode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- 【python】str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法(转)
- python Unicode与str decode与encode 中文输出
- decode、encode、unicode解码
- URLEncoder.encode(str,"编码") new URLDecoder().decode(str,"编码")
- URLEncoder.encode(str,"编码") new URLDecoder().decode(str,"编码")
- URLEncoder.encode(str,"编码") new URLDecoder().decode(str,"编码")
- Unicode Python encode decode的知识点总结
- 字符编码,pyton中的encode,decode,unicode()
- python中 encode,decode,unicode,utf-8
- python中的编码问题unicode, encode, decode
- 一个有意思的网站…………
- linux常见问题(系统篇)
- 我问一下用C#写网页以后怎么美工合到一起啊?????高手进
- 用来编译python2.4的编译器
- 串口学习笔记(一)
- unicode .decode /str.encode方法
- Delphi中流对象的应用
- mysql---python
- MSComm控件属性大揭秘
- Delphi源码排列
- 音乐手记之民谣二:Chamber
- native2ascii
- QQ2005贺岁版登录口令加密算法及其源代码
- “内地首例涉台软件著作权案”律师点评