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

 

 

________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.
arrow
arrow
    全站熱搜

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