[compiled python files]

  As an important speed-up of the start-up time for short programs that use a lot of standard modules, if a file called spam.pyc exists in the directory where spam.py is found, this is assumed to contain an already-“byte-compiled” version of the module spam. The modification time of the version of spam.py used to create spam.pyc is recorded in spam.pyc, and the .pyc file is ignored if these don’t match.

  Normally, you don’t need to do anything to create the spam.pyc file. Whenever spam.py is successfully compiled, an attempt is made to write the compiled version to spam.pyc. It is not an error if this attempt fails; if for any reason the file is not written completely, the resulting spam.pyc file will be recognized as invalid and thus ignored later. The contents of the spam.pyc file are platform independent, so a Python module directory can be shared by machines of different architectures.

Some tips for experts:

  • When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in .pyo files. The optimizer currently doesn’t help much; it only removesassert statements. When -O is used, all bytecode is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.

  • Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only __doc__ strings are removed from the bytecode, resulting in more compact .pyo files. Since some programs may rely on having these available, you should only use this option if you know what you’re doing.

  • 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.

  • When a script is run by giving its name on the command line, the bytecode for the script is never written to a .pyc or .pyo file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module. It is also possible to name a .pyc or .pyo file directly on the command line.

  • It is possible to have a file called spam.pyc (or spam.pyo when -O is used) without a file spam.py for the same module. This can be used to distribute a library of Python code in a form that is moderately hard to reverse engineer.

  • The module compileall can create .pyc files (or .pyo files when -O is used) for all modules in a directory.

参考: http://docs.python.org/2.7/tutorial/modules.html?highlight=pyc#compiled-python-files

compiled python files的更多相关文章

  1. “Compiled” Python files

    To speed up loading modules, Python caches the compiled version of each module in the __pycache__ di ...

  2. [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 ...

  3. py, pyc, pyw, pyo, pyd 及发布程序时的选择 Compiled Python File (.pyc)

    Python 程序扩展名(py, pyc, pyw, pyo, pyd)及发布程序时的选择 - 司开星的专栏 - CSDN博客 https://blog.csdn.net/chroming/artic ...

  4. 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是一种解释性的语言,但是这种说法 ...

  5. Python模块学习

    6. Modules If you quit from the Python interpreter and enter it again, the definitions you have made ...

  6. 记录一下跟Python有关的几个拓展名

    .py python文本源码文件,也可以用python.exe直接运行 .pyw 也是python的文本源码文件,但是默认由pythonw.exe打开,而且不显示命令行窗口,带GUI的python代码 ...

  7. Python Tutorial 学习(六)--Modules

    6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...

  8. [译]The Python Tutorial#6. Modules

    [译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使 ...

  9. Python Module模块

    模块 https://docs.python.org/zh-cn/3/tutorial/modules.html 模块的概念被高级语言广泛使用. Python的定义 一个包括Python定义和语句的文 ...

随机推荐

  1. A1486. 树(王康宁)

    题目:http://www.tsinsen.com/A1486 题解: 其实看到和路径有关的就应该想到点分治. 我们找出重心之后遍历每一棵子树得到它的 { x=经过特殊点的个数,y=到rt的异或和} ...

  2. Amazium源码分析:(1)基本介绍

    前言 Amazium是一个网格系统的框架,分析该源码的目的是了解网格系统的实现. 网格系统 定义:设计美观页面布局的方式,上图能够很直观的了解什么是网格系统. 基本概念 column: 列. gutt ...

  3. linux sed 命令

    转载:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行 ...

  4. dede栏目调用大全

    A:侧边栏常用的当前栏目的父栏目调用(5.7) 1.在include/common.inc.php增加函数 function getTopCategoryName($cid=0) { global $ ...

  5. 【英语】Bingo口语笔记(40) - [aʊ]的发音规则

    [aʊ]的发音规则 先发音标的音再去拼出单词的读音down

  6. NetBeans-xdebug的安装

    如果总是提示正在连接,ok,应该是没有装xdebug; 1,下载Php版本对应的xdebug.dll文件,以下是官方提供的网址,可以智能判断环境,给出下载链接和使用指南 http://www.xdeb ...

  7. ORACLE创建、修改、删除序列

    ORACLE没有象SQL SERVER中一样的自增加字段,要实现只能通过SEQUENCE来实现. 1.创建序列语法:(需要CREATE SEQUENCE系统权限) CREATE SEQUENCE 序列 ...

  8. 实用js+css多级树形展开效果导航菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. AJAX overrideMimeType作用

    我们经常在AJAX代码中发现如下代码:   if (http_request.overrideMimeType) {    http_request.overrideMimeType("te ...

  10. HUD 2717 Catch That Cow

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...