天天看點

UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)

Python在進行中文編碼時經常會出現亂碼,并報如标題那樣的錯誤,這時隻要在代碼起始處加入如下代碼即可解決:

import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )