Python's character set processing is really egg ache, currently use UTF-8 majority, then the default character set is ASCII, so we need to change to Utf-8
View current system Character set
Copy CodeThe code is as follows:
Import Sys
Print sys.getdefaultencoding ()
Perform:
Copy CodeThe code is as follows:
[Root@lee ~]# python a.py
Ascii
Modify into Utf-8
Copy CodeThe code is as follows:
Import Sys
Sys.setdefaultencoding (' Utf-8 ')
Print sys.getdefaultencoding ()
Perform:
Copy CodeThe code is as follows:
[Root@lee ~]# python a.py
Traceback (most recent):
File "a.py", line 4, in
Sys.setdefaultencoding (' Utf-8 ')
Attributeerror: ' Module ' object has no attribute ' setdefaultencoding '
Hint: attributeerror: ' Module ' object has no attribute ' setdefaultencoding '?
Later after looking for relevant information, only to find that the earlier version can be directly sys.setdefaultencoding (' Utf-8 '), the new version needs to reload first
Copy the Code code as follows:
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')
Print sys.getdefaultencoding ()
Perform
Copy the Code code as follows:
[Root@lee ~]# python a.py
Utf-8