Traceback (most recent call last):
File "D:\3S_PC\python\3S_AUTO\FileStudy.py", line 521, in <module>
parseXML(xmlPath)
File "D:\3S_PC\python\3S_AUTO\FileStudy.py", line 496, in parseXML
print ('{}, Unexpected error:{}'.format(testName, sys.exc_info()))
UnicodeEncodeError: 'cp950' codec can't encode character '\xf1' in position 215: illegal multibyte sequence
原因:
使用 windows cmd print時會轉碼為cp950,但python使用unicode
SOL:
try:
for item in sortlistFileInfo3:
if (len(item) == 4):
print('{:<10d},{:<10d},{:<10d},{:45s},{}'.format(nIndex,
item[0],
item[1],
item[2].encode("utf8").decode("cp950", "ignore"),
item[3].encode("utf8").decode("cp950", "ignore")))
else:
print('!!!{:<10d},{}'.format(nIndex, item))
nIndex += 1
except:
print ('Show listFile3, Unexpected error:{}'.format(sys.exc_info()))
沒有留言:
張貼留言