“Compiled” Python files
To speed up loading modules, Python caches the compiled version of each module in the __pycache__
directory under the name module.version.pyc
, where the version encodes the format of the compiled file; it generally contains the Python version number. For example, in CPython release 3.3 the compiled version of spam.py would be cached as __pycache__/spam.cpython-33.pyc
. This naming convention allows compiled modules from different releases and different versions of Python to coexist.
Python checks the modification date of the source against the compiled version to see if it’s out of date and needs to be recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.
Python does not check the cache in two circumstances. First, it always recompiles and does not store the result for the module that’s loaded directly from the command line. Second, it does not check the cache if there is no source module. To support a non-source (compiled only) distribution, the compiled module must be in the source directory, and there must not be a source module.
Some tips for experts:
- You can use the
-O
or-OO
switches on the Python command to reduce the size of a compiled module. The-O
switch removes assert statements, the-OO
switch removes both assert statements and __doc__ strings. Since some programs may rely on having these available, you should only use this option if you know what you’re doing. “Optimized” modules have a .pyo rather than a .pyc suffix and are usually smaller. Future releases may change the effects of optimization. - A program doesn’t run any faster when it is read from a
.pyc
or.pyo
file than when it is read from a.py
file; the only thing that’s faster about.pyc
or.pyo
files is the speed with which they are loaded. - The module
compileall
can create .pyc files (or .pyo files when-O
is used) for all modules in a directory. - There is more detail on this process, including a flow chart of the decisions, in PEP 3147.
“Compiled” Python files的更多相关文章
- compiled python files
[compiled python files] As an important speed-up of the start-up time for short programs that use a ...
- [TypeScript] Loading Compiled TypeScript Files in Browser with SystemJS
TypeScript outputs JavaScript, but what are you supposed to do with it? This lesson shows how to tak ...
- py, pyc, pyw, pyo, pyd 及发布程序时的选择 Compiled Python File (.pyc)
Python 程序扩展名(py, pyc, pyw, pyo, pyd)及发布程序时的选择 - 司开星的专栏 - CSDN博客 https://blog.csdn.net/chroming/artic ...
- py, pyc, pyw, pyo, pyd Compiled Python File (.pyc) 和Java或.NET相比,Python的Virtual Machine距离真实机器的距离更远
https://my.oschina.net/renwofei423/blog/17404 1. PyCodeObject与Pyc文件 通常认为,Python是一种解释性的语言,但是这种说法 ...
- Python模块学习
6. Modules If you quit from the Python interpreter and enter it again, the definitions you have made ...
- 记录一下跟Python有关的几个拓展名
.py python文本源码文件,也可以用python.exe直接运行 .pyw 也是python的文本源码文件,但是默认由pythonw.exe打开,而且不显示命令行窗口,带GUI的python代码 ...
- Python Tutorial 学习(六)--Modules
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...
- [译]The Python Tutorial#6. Modules
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使 ...
- Python Module模块
模块 https://docs.python.org/zh-cn/3/tutorial/modules.html 模块的概念被高级语言广泛使用. Python的定义 一个包括Python定义和语句的文 ...
随机推荐
- iisreset和w3wp的关系
iisreset是iis自带一个命令行工具.用法: iisreset [computername] /RESTART 停止然后重新启动所有 Internet 服务. /START ...
- 伪静态<-> 动态页,伪静态,真静态的比较和选择
动态页,伪静态,真静态优缺点的比较 动态页不利于SEO优化. 动态页常常因为传参数的缘故后面会带一连串的问号.而搜索引擎会因为里面问号导致死循(机器人陷阱Spidertraps),所以带问号的地址搜索 ...
- 查看Nginx、apache、MySQL和PHP的编译参数
1.nginx编译参数:#/usr/local/nginx/sbin/nginx -V2.apache编译参数:# cat /usr/local/apache/build/config.nice3.p ...
- centos 运用ssh的rsa算法实现无密码登录
ssh 公钥和私钥原理 1.客户端机子生成私钥和公钥,将公钥放到服务器证书中,然后就可以实现免密码登录.(服务器认证文件要有该登录用户的读执行权限) 2.a登录b: a机子:test01账号(b也要建 ...
- java 面向对象编程--第17章 I/O系统
1.I/O操作指的是输入和输出流的操作.相对内存而言,当我们从数据源中将数据读取到内存中,就是输入流,也叫读取流.当我们将内存中处理好的数据写入数据源,就是输出流,也叫写入流. 2.流按照内容分类:字 ...
- tortoisegit教程
tortoisegit教程: http://www.mamicode.com/info-detail-311565.html https://my.oschina.net/longxuu/blog/1 ...
- js基础之COOKIE
一.COOKIE的封装函数 function setCookie(name,value,eDate){ var oDate = new Date(); oDate.setDate(oDate.getD ...
- winform按钮和子按钮
实现目标: 一.两组按钮1和2,其中按钮2有两个子按钮, (1)当选按钮1时,按钮2和其子按钮不选中: (2)选中按钮2或其子按钮3和4时,1不选中 (3)选中按钮2时,默认选中其子按钮3 (4)选中 ...
- wcf精通1-15
随笔- 197 文章- 0 评论- 3407 十五天精通WCF——第一天 三种Binding让你KO80%的业务 转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是 ...
- USB鼠标按键驱动
现象:把USB设备接到PC 1. 右下角弹出"发现android phone" 2. 跳出一个对话框,提示你安装驱动程序 问1. 既然还没有"驱动程序",为何能 ...