Python面試真題-python程序中文輸出問題怎么解決?
【Python面試真題】-Python程序中文輸出問題怎么解決?
用encode和decode
如:
1 import os.path 2 import xlrd,sys 3 4 Filename=’/home/tom/Desktop/1234.xls’ 5 if not os.path.isfile(Filename): 6 raise NameError,”%s is not a valid filename”%Filename 7 8 bk=xlrd.open_workbook(Filename) 9 shxrange=range(bk.nsheets) 10 print shxrange 11 12 for x in shxrange: 13 p=bk.sheets()[x].name.encode(‘utf-8′) 14 print p.decode(‘utf-8′)