Python's character set processing is really a pain in the egg, the current use of UTF-8 mostly, and then the default character set is ASCII, so we need to change to Utf-8
View the current system character set
Copy Code code as follows:
Import Sys
Print sys.getdefaultencoding ()
Perform:
Copy Code code as follows:
[Root@lee ~]# python a.py
Ascii
Modified into Utf-8
Copy Code code as follows:
Import Sys
Sys.setdefaultencoding (' Utf-8 ')
Print sys.getdefaultencoding ()
Perform:
Copy Code code as follows:
[Root@lee ~]# python a.py
Traceback (most recent call last):
File "a.py", line 4, in <module>
Sys.setdefaultencoding (' Utf-8 ')
Attributeerror: ' setdefaultencoding ' of ' module ' object has no attribute
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 be reload first
Copy Code code as follows:
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')
Print sys.getdefaultencoding ()
Perform
Copy Code code as follows:
[Root@lee ~]# python a.py
Utf-8