[深入Python]sys.modules
Python中所有加载到内存的模块都放在sys.modules。当import一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将模块的名字加入到正在调用import的模块的Local名字空间中。如果没有加载则从sys.path目录中按照模块名称查找模块文件,模块文件可以是py、pyc、pyd,找到后将模块载入内存,并加入到sys.modules中,并将名称导入到当前的Local名字空间。
详细信息参考:
http://www.cnblogs.com/qq78292959/archive/2013/05/17/3083961.html
扩展知识:
Python在import其它模块时,是从sys.path中搜索的。
sys.path的初始值会受到PYTHONPATH、PYTHONHOME等环境变量的影响。
也可以在脚本运行过程中动态修改sys.path从而import自己需要的模块。
[深入Python]sys.modules的更多相关文章
- python sys.modules模块
sys.modules是一个全局字典,该字典是python启动后就加载在内存中.每当程序员导入新的模块,sys.modules都将记录这些模块.字典sys.modules对于加载模块起到了缓冲的作用. ...
- python sys.modules 和 sys.path 及 __name__
1.sys.modules 存放已经缓存的模块 值是dict 2.sys.path 搜索路径 值是list 3.if __name__= __main__ 可以看成python的程序入口,如果直接执行 ...
- python sys模块
sy模块主要用于:解析器及环境 命令行参数 python xx.py xx1 xx2注:xx.py: sys.argv[0] 脚本名称 xx1 sys.argv[1] 第1个参数退出程序 sys.ex ...
- programing Python --Sys module
Recall that every python module has a built_in __name__ variable that python sets to the __main__ st ...
- Python——sys模块
七.sys模块 sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传递参数. sys.exit([arg]): 程序中间的退出,arg=0为正常退出. sys.getdefaulten ...
- Python sys.md
sys-System-specific Configuration Interpreter Settings sys包含用于访问解释器的编译时或运行时配置设置的属性和函数. Build-time Ve ...
- python sys模块使用详情
python常用模块目录 sys模块提供了一系列有关Python运行环境的变量和函数.1.sys.argv可以用sys.argv获取当前正在执行的命令行参数的参数列表(list).变量解释sys.ar ...
- python sys模块和序列化模块
sys模块是与python解释器交互的一个接口: sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0),错误退出sys.exit( ...
- sys.modules[__name__]
A way to get a handle to the current running module in Python: import sys module = sys.modules[__nam ...
随机推荐
- ddd
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqiYF+Y89+3wKwCtvDOCJ6qQifvC+snwHsZEy6naujvCHXkeB/BcDDwnq ...
- C#网络爬虫
CronMaker is a utility which helps you to build cron expressions. CronMaker uses Quartz open source ...
- windows+caffe(四)——创建模型并编写配置文件+训练和测试
1.模型就用程序自带的caffenet模型,位置在 models/bvlc_reference_caffenet/文件夹下, 将需要的两个配置文件,复制到myfile文件夹内 2. 修改solver. ...
- noi 4978 宠物小精灵之收服
题目链接:http://noi.openjudge.cn/ch0206/4978/ 二维费用背包 在最后找还剩多少体力的时候,直接找到第二维,当结果 f[n][i] == f[n][m] 时,就说明已 ...
- js产生随机数并加入数组
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- 【iOS】Foundation框架 学习笔记
1.数组 OC数组不能存放nil值OC数组只能存放OC对象.不能存放非OC对象类型,比如int.struct.enum等 ====================================== ...
- faster alter table add column
Create a new table (using the structure of the current table) with the new column(s) included. execu ...
- linux passwd文件解析
#cat/etc/passwd root:x:::Superuser:/: daemon:x:::Systemdaemons:/etc: bin:x:::Ownerofsystemcommands:/ ...
- centos7 docker tomcat7
docker run --name=tomcat7_tmp -ti centos7/jdk7 /bin/bash cd /home wget http://apache.fayea.com/tomca ...
- CentOS6.5 安装 tomcat
1.首先下载tomcat.tar.gz包 http://tomcat.apache.org/download-70.cgi 2.移动到目标文件夹 mv tomcat.tar.gz /usr/tomca ...