“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
-Oor-OOswitches on the Python command to reduce the size of a compiled module. The-Oswitch removes assert statements, the-OOswitch 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
.pycor.pyofile than when it is read from a.pyfile; the only thing that’s faster about.pycor.pyofiles is the speed with which they are loaded. - The module
compileallcan create .pyc files (or .pyo files when-Ois 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定义和语句的文 ...
随机推荐
- webBrowser1执行函数
IHTMLWindow2 Win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;string s = "alert('x');& ...
- centOS wget的安装和使用
CentOS wget是一个从网络上自动下载文件的自由工具.它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理. 所谓的自动下载是指,CentOS wget可以在用户退出系统的之后在后台执行 ...
- SpringMVC 配置定时执行任务
1.在SpringMVC配置文件中添加 xmlns:task="http://www.springframework.org/schema/task" http://www.spr ...
- vs版本与.net framework 版本对应
vs2002 .net framework 1.0 vs2003 版本号:7.x .net framework 1.1 window server 2003 vs2005 版本号:8.x . ...
- uva 10118
10118 - Free Candies Time limit: 30.000 seconds Little Bob is playing a game. He wants to win some c ...
- PHP中MySql函数收集
1.array mysql_fetch_assoc ( resource $result ) 从结果集中取得一行作为关联数组 说明: 返回对应结果集的关联数组,并且继续移动内部数据指针. 参数:re ...
- Word文档增加快捷键
- apache2.4域名配置参数
apache2.4和 2.2版本的配置有区别 2.4的配置如下 <VirtualHost *:80>DocumentRoot /www/web/projectServerName www. ...
- sql 查询强制使用HASH连接性能测试比较
HASH JOIN 散列连接 hash join是CBO 做大数据集连接时的常用方式.优化器扫描小表(或数据源),利用连接键(也就是根据连接字段计算hash 值)在内存中建立hash表,然后扫描大表, ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...