各位大侠,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 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试
在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......
像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:
Python code:
>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......
在list中添加一个类的局部变量 这样做是否合法 请看下面例子:
Python code:
class A():
def __init__( self ):
self.__a = 0
self.__b = 'hello'
def get_a( self ):
ret ......
Python 怎样启动远程的QTP,然后执行某个路径下的TEST ?
VB可以这样:
Set qtApp = CreateObject("QuickTest.Application", "192.168.0.102")
qtApp.Launch
qtApp.Visible = T ......