python3 the reload (sys) and sys.setdefaultencoding ( 'utf-8')

Usually we will carry out in order to prevent garbled bit operating
Import SYS
reload (SYS)
sys.setdefaultencoding ( 'UTF-8')
but this is python2 wording, but in this python3 the need no longer exists, what it will not do so practical significance.
If you do that there will be some mistakes

sys.setdefaultencoding ( 'UTF-. 8')
AttributeError: Module1 'SYS' attribute has NO 'setdefaultencoding'
in Python2.x due str and no significant difference between the byte, often rely on the conversion defaultencoding do.
With a clear distinction str python3 and the type byte, another type of encoding to be specified explicitly convert from one type to.

Therefore, the above syntax can be changed

import importlib,sys
importlib.reload(sys)

Guess you like

Origin www.cnblogs.com/lxc1997ye/p/11665521.html