Brief description:
Note: When you reuse the import statement multiple times, the module is not reloaded, but the memory address of the module is referenced to the local environment variable
#!/usr/bin/env python#-*-coding:utf-8-*-"" "# # authors:limanman# 51ctobg:http://xmdevops.blog.51cto.com/# Purpose:# "" "# Description: Import Public Module Imports systry:sys.setdefaultencoding (' Utf-8 ') except Exception, e:print e reload (SYS) sys.setd Efaultencoding (' Utf-8 ') print sys.getdefaultencoding () # Description: Import other modules if __name__ = = ' __main__ ': Pass
Reload:
Description: The module has been loaded to reload, generally used for the original module changes and other special cases, reload before the module must have been import, but it should be noted that the used instance will also use the old module, and the newly generated instance will use the new module, Reload after the original memory address
#!/usr/bin/env python#-*-coding:utf-8-*-"" "# # authors:limanman# 51ctobg:http://xmdevops.blog.51cto.com/# Purpose:# "" "# Description: Import Public Module Imports systry:sys.setdefaultencoding (' Utf-8 ') except Exception, e:print e reload (SYS) sys.setd Efaultencoding (' Utf-8 ') print sys.getdefaultencoding () # Description: Import other modules if __name__ = = ' __main__ ': Pass
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/88/35/wKiom1frif2BKsmmAAEhOxOr39o402.png "title=" Del.png "alt=" Wkiom1frif2bksmmaaehoxor39o402.png "/>
Description: Many people do not name why reload () SYS is required to use setdefaultencoding to set the encoding, in fact, because the interpreter initialization is pre-executed/usr/lib64/python2.7/site.py, And in its 554 lines of code del sys.setdefaultencoding deleted this method, in fact, you import sys only points to the setdefaultencoding attribute of the SYS module address, So we need to reload again. Restore this method
This article is from the "ζ Automated operation and maintenance development Road ζ" blog, please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1857444
Basic Primer _python-modules and packages. Why Reload (SYS) before setdefaultencoding?