各位大侠,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'
汗,谢谢
我刚发完帖,突然想起是函数用错了.
呵呵
相关问答:
s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,fff777ggg'
用正则表达式取出 前后字母相同的数据 结果如下:
111 ddd
谢谢~
Python code:
import re
s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,ff ......
在文本文件中匹配项包含中文
如内容为:gamename=中文
key=天下
文本文件的编码的文件为utf-8
python代码如下:
# -*- coding:UTF-8 -*-
contents=open(from_pa ......
#将GB2312格式转为UTF-8格式
f = codecs.open('e:\TestResult.xml', "rb", "gb2312")
text = f.read().encode("utf-8")
  ......
Python 怎样启动远程的QTP,然后执行某个路径下的TEST ?
VB可以这样:
Set qtApp = CreateObject("QuickTest.Application", "192.168.0.102")
qtApp.Launch
qtApp.Visible = T ......