易截截图软件、单文件、免安装、纯绿色、仅160KB

各位大侠,Python 编码问题

例子是这样的:

>>> str1 = '小狗'
>>> str1
'小狗'
>>> str1.encode('utf-8')
b'\xe5\xb0\x8f\xe7\x8b\x97'
>>> str2 = str1.encode('utf-8')
>>> str2
b'\xe5\xb0\x8f\xe7\x8b\x97'

我要还原为'小狗'用哪种编码格式
注:python 2.4和python 3.1

>>>str1.encode('gbk')
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
str2.encode('gbk')
AttributeError: 'bytes' object has no attribute 'encode'

汗,谢谢
我刚发完帖,突然想起是函数用错了.
呵呵


相关问答:

Python中的Unicode在Delphi如何还原成Gb2312?

已知Python 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试

在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......

[提问]Python 如何忽略 whitespace 读入

像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:
Python code:

>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......

python list中添加类对象的问题

在list中添加一个类的局部变量 这样做是否合法 请看下面例子:
Python code:

class A():
def __init__( self ):
self.__a = 0
self.__b = 'hello'
def get_a( self ):
ret ......

Python 怎样启动远程的QTP?

Python 怎样启动远程的QTP,然后执行某个路径下的TEST ?

VB可以这样:
Set qtApp = CreateObject("QuickTest.Application", "192.168.0.102")
qtApp.Launch
qtApp.Visible = T ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号