pythonlist輸出中文
A. python 中怎麼把類似這樣的'\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82'轉換成漢字輸出
首先你要確定這是漢子的十六進制碼,還有他的編碼方式是什麼
我姑且算是utf-8來說明吧
把上述十六進制轉成二進制,python byte類型(記不清是否可以)也可以手動轉二進制
p3使用str(s, 'utf8') p2使用 s.decode('utf8')來對二進制解碼
輸出漢字
你要確定上述十六進制碼是漢字轉過來的,否則無論嘗試何種解碼方式皆不可得
B. python如何輸入輸出中文
1,在文件夾中新建一個test.py的文件。
C. python中如何輸出字典的中文
#coding:utf-8
dic={'張三':2,'李四':3,'王五':5}
line=None
forkeyindic:
ifline!=None:
line+=","
else:
line="{"
line+="'"+key+"':"+str(dic[key])
line+="}"
printline
D. 怎麼使用Python語言中輸出中文字元
# -*- coding: utf-8 -*-
import codecs
content = u'你好'
f = codecs.open('c:/1.txt','w','utf-8')
f.write(content)
E. python 將漢字 輸出GB2312
我用的python3.5 用ascii函數處理
s="中文"
lst=[]
forcins:
lst.append(int('0x'+ascii(c)[3:7],16))
print(lst)
輸出是:[20013, 25991]
F. python 列表寫入文件時怎麼變成中文
list1=[u'u96f7u519b',u'u9eceu4e07u5f3a',u'u6d2au950b',u'u5218u5fb7',u'u96f7u519b',u'u6797u658c',u'u5218u82b9',u'u8bb8u8fbeu6765',u'u96f7u519b',u'u9eceu4e07u5f3a']
importcodecs
f=codecs.open('list1.txt','w','utf-16')
foriinlist1:
i=i+''
f.write(i,)
f.close()
G. python語言怎麼來輸出中文字元
python2的話:
print'品牌id'.decode('utf-8')
print'xe5x93x81xe7x89x8cid'.decode('utf-8')
如果是python3:
就直接print('中文')
H. Python 輸出中文問題,真是整瘋了。。。
選擇# -*- coding: utf-8-*-,因為你文件編碼是utf-8的。
也可以這樣,形式簡單一些:
#encoding:utf-8
python中有兩種類型的字元串:普通的str和unicode。一般情況下,處理中文數據推薦使用unicode類型,因為這樣就不用考慮編碼的問題。到了顯示或輸出時再轉換為存儲類型(utf-8、GBK)。但unicode本身是不能輸出的,它只是一種內部編碼。
看以下示例代碼:
#unicode轉str,utf-8編碼
u'哈哈哈哈'.encode('utf-8','ignore')
#unicode轉str,GBK編碼
u'哈哈哈哈'.encode('gbk','ignore')
#str轉unicode,其中str為utf-8編碼
'哈哈哈哈'.decode('utf-8','ignore')
I. python中如何正確列印元素為中文字元串的list
用個for循環吧
for z in i:
print z
這樣就可以了
如果是字典的話
d = {'中文':'中國'}:
print '%s : %s' % (k,v) for k,v in d.items()
就可以很輕松的實現列印了
J. python怎麼輸出中文
打開Python編譯器,在代碼的第一行設置編碼格式,加入#-*-coding:utf-8-*-即可。
相關推薦:《Python基礎教程》
如下: