码迷,mamicode.com
首页 > 编程语言 > 详细

python sys.modules模块

时间:2018-05-21 21:15:02      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:pytho   win   ati   code   启动   thread   name   序列化   程序员   

sys.modules是一个全局字典,该字典是python启动后就加载在内存中。每当程序员导入新的模块,sys.modules都将记录这些模块。字典sys.modules对于加载模块起到了缓冲的作用。当某个模块第一次导入,字典sys.modules将自动记录该模块。当第二次再导入该模块时,python会直接到字典中查找,从而加快了程序运行的速度。

字典sys.modules具有字典所拥有的一切方法,可以通过这些方法了解当前的环境加载了哪些模块

    import  sys

    print sys.modules.keys()

    print sys.modules.values()

    print sys.modules["os"]

 

import sys
print(sys.modules[__name__])
print(sys.modules.values())
print(sys.modules.keys())
print(sys.modules.items())
<module __main__ from D:/python自动化21/untitled/07/上课/序列化.py>

dict_values([<module builtins (built-in)>, <module sys (built-in)>, <module _frozen_importlib (frozen)>, <module _imp (built-in)>, <module _warnings (built-in)>, <module _thread (built-in)>, <module _weakref (built-in)>, <module _frozen_importlib_external (frozen)>, <module io (built-in)>, <module marshal (built-in)>, <module nt (built-in)>, <module winreg (built-in)>, <module zipimport (built-in)>, <module encodings from D:\\python36\\lib\\encodings\\__init__.py>, <module codecs from D:\\python36\\lib\\codecs.py>, <module _codecs (built-in)>, <module encodings.aliases from D:\\python36\\lib\\encodings\\aliases.py>, <module encodings.utf_8 from D:\\python36\\lib\\encodings\\utf_8.py>, <module _signal (built-in)>, <module __main__ from D:/python自动化21/untitled/07/上课/序列化.py>, <module encodings.latin_1 from D:\\python36\\lib\\encodings\\latin_1.py>, <module io from D:\\python36\\lib\\io.py>, <module abc from D:\\python36\\lib\\abc.py>, <module _weakrefset from D:\\python36\\lib\\_weakrefset.py>, <module site from D:\\python36\\lib\\site.py>, <module os from D:\\python36\\lib\\os.py>, <module errno (built-in)>, <module stat from D:\\python36\\lib\\stat.py>, <module _stat (built-in)>, <module ntpath from D:\\python36\\lib\\ntpath.py>, <module genericpath from D:\\python36\\lib\\genericpath.py>, <module ntpath from D:\\python36\\lib\\ntpath.py>, <module _collections_abc from D:\\python36\\lib\\_collections_abc.py>, <module _sitebuiltins from D:\\python36\\lib\\_sitebuiltins.py>, <module sysconfig from D:\\python36\\lib\\sysconfig.py>]) dict_keys([builtins, sys, _frozen_importlib, _imp, _warnings, _thread, _weakref, _frozen_importlib_external, _io, marshal, nt, winreg, zipimport, encodings, codecs, _codecs, encodings.aliases, encodings.utf_8, _signal, __main__, encodings.latin_1, io, abc, _weakrefset, site, os, errno, stat, _stat, ntpath, genericpath, os.path, _collections_abc, _sitebuiltins, sysconfig]) dict_items([(builtins, <module builtins (built-in)>), (sys, <module sys (built-in)>), (_frozen_importlib, <module _frozen_importlib (frozen)>), (_imp, <module _imp (built-in)>), (_warnings, <module _warnings (built-in)>), (_thread, <module _thread (built-in)>), (_weakref, <module _weakref (built-in)>), (_frozen_importlib_external, <module _frozen_importlib_external (frozen)>), (_io, <module io (built-in)>), (marshal, <module marshal (built-in)>), (nt, <module nt (built-in)>), (winreg, <module winreg (built-in)>), (zipimport, <module zipimport (built-in)>), (encodings, <module encodings from D:\\python36\\lib\\encodings\\__init__.py>), (codecs, <module codecs from D:\\python36\\lib\\codecs.py>), (_codecs, <module _codecs (built-in)>), (encodings.aliases, <module encodings.aliases from D:\\python36\\lib\\encodings\\aliases.py>), (encodings.utf_8, <module encodings.utf_8 from D:\\python36\\lib\\encodings\\utf_8.py>), (_signal, <module _signal (built-in)>), (__main__, <module __main__ from D:/python自动化21/untitled/07/上课/序列化.py>), (encodings.latin_1, <module encodings.latin_1 from D:\\python36\\lib\\encodings\\latin_1.py>), (io, <module io from D:\\python36\\lib\\io.py>), (abc, <module abc from D:\\python36\\lib\\abc.py>), (_weakrefset, <module _weakrefset from D:\\python36\\lib\\_weakrefset.py>), (site, <module site from D:\\python36\\lib\\site.py>), (os, <module os from D:\\python36\\lib\\os.py>), (errno, <module errno (built-in)>), (stat, <module stat from D:\\python36\\lib\\stat.py>), (_stat, <module _stat (built-in)>), (ntpath, <module ntpath from D:\\python36\\lib\\ntpath.py>), (genericpath, <module genericpath from D:\\python36\\lib\\genericpath.py>), (os.path, <module ntpath from D:\\python36\\lib\\ntpath.py>), (_collections_abc, <module _collections_abc from D:\\python36\\lib\\_collections_abc.py>), (_sitebuiltins, <module _sitebuiltins from D:\\python36\\lib\\_sitebuiltins.py>), (sysconfig, <module sysconfig from D:\\python36\\lib\\sysconfig.py>)])

 

python sys.modules模块

标签:pytho   win   ati   code   启动   thread   name   序列化   程序员   

原文地址:https://www.cnblogs.com/zhaojingyu/p/9069076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!