1, about setdefaultencoding must reload (SYS):
To call setdefaultencoding, you have to reload the Sys module first, because the import statement here is not actually the first import statement of Sys, that is, this may be the second to third time the Sys module imports, This is just a reference to SYS and can only be reload for reloading.
So why reload, and direct reference can not call the function? Because the setdefaultencoding function is deleted after being called by the system, it is not already in the import reference, so it must be reload once sys module, so setdefaultencoding will be available To modify the current character encoding of the interpreter in the code.
In the Python installation directory of the Lib folder, there is a file called site.py, in which you can find main ()--setencoding ()-->sys.setdefaultencoding (encoding), Because this site.py is automatically loaded every time the Python interpreter is started, the main function is executed every time, and the setdefaultencoding function is removed.
Python scattered Knowledge Point records