close

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

 

 

[python] &apos;cp950&apos; , illegal , U

________________________________
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 天才R 的頭像
    天才R

    做 個 有 趣 的 人

    天才R 發表在 痞客邦 留言(0) 人氣()