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′)