# coding = ASCII
Import JSON
Import Pickle
Import Sys
Import OS
- The first parameter in the Decode () and Encode methods is the encoded format, and the second is the type of processing to be used when the conversion occurs (ignore: ignore, cannot convert, or empty; Replace: With? instead
Because character encoding is Unicode by default in Python3, all direct calls to the Encode method implement character encoding conversions, since ASSCII characters do not contain Chinese characters, so decode
Will cause error, is used after replace although can avoid error, but will eventually decode after the result of Chinese as?? The results
# character transcoding implementation
Test = "Hello"
#获得当前文件编码格式
Print (sys.getdefaultencoding ())
Print (Test.encode ("Utf-8"). Decode ("ASCII", "replace"). Encode ("ASCII", "replace"). Decode ("Utf-8"))
EXEC (test)
Python error Unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 7-8: Ordinal not in range (128)