.py

python文本源码文件,也可以用python.exe直接运行

.pyw

也是python的文本源码文件,但是默认由pythonw.exe打开,而且不显示命令行窗口,带GUI的python代码可以使用这个,比如自带的idle.pyw

.pyc

由.py文件编译生成的二进制文件,执行速度可能会快点,但是相对于.py文件体积上的减小并不是很明显,还有个缺点是不同的python版本生成的.pyc文件不通用!

.pyo

这个也是由.py编译生成的二进制文件,暂时理解为相对于.pyc优化了一下的东西

.pyd

说是什么python的动态链接库文件,不太懂,搞清楚了再来补充

另外,贴一下python自带的chm文件中关于“编译后的模块”的说明:

6.1.3. “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 removes assert 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.

记录一下跟Python有关的几个拓展名的更多相关文章

  1. 记录遇到的Python陷阱和注意点

    最近使用Python的过程中遇到了一些坑,例如用datetime.datetime.now()这个可变对象作为函数的默认参数,模块循环依赖等等. 在此记录一下,方便以后查询和补充. 避免可变对象作为默 ...

  2. 记录两个python的小问题

    使用python也前前后后也一个月的样子,记录两个一直没注意的问题. 1. 元组的使用(拼接字符串) 直接看下面的代码: >>> kel = 'some','strings' > ...

  3. 记录我的 python 学习历程-Day02-while 循环/格式化输出/运算符/编码的初识

    一.流程控制之--while 循环 循环就是重复做同一件事,它可以终止当前循环,也可以跳出这一次循环,继续下一次循环. 基本结构(基本循环) while 条件: 循环体 示例 # 这是一个模拟音乐循环 ...

  4. 记录我的 python 学习历程-Day06 is id == / 代码块 / 集合 / 深浅拷贝

    一.is == id 用法 在Python中,id是内存地址, 你只要创建一个数据(对象)那么就会在内存中开辟一个空间,将这个数据临时加载到内存中,这个空间有一个唯一标识,就好比是身份证号,标识这个空 ...

  5. 首篇-记录自己学习python之路!

    对于自己学习python的目的比较明确——爬虫和量化. 目前找了一些资源进行学习,先进行量化方面的学习,爬虫滞后.目前的目标是“180天掌握尽可能多的量化能力”! 以后定时发送自己学习思考内容以作自己 ...

  6. 记录我的 python 学习历程-Day12 生成器/推导式/内置函数Ⅰ

    一.生成器 初识生成器 生成器的本质就是迭代器,在python社区中,大多数时候都把迭代器和生成器是做同一个概念. 唯一的不同就是: 迭代器都是Python给你提供的已经写好的工具或者通过数据转化得来 ...

  7. 记录我的 python 学习历程-Day13 匿名函数、内置函数 II、闭包

    一.匿名函数 以后面试或者工作中经常用匿名函数 lambda,也叫一句话函数. 课上练习: # 正常函数: def func(a, b): return a + b print(func(4, 6)) ...

  8. 记录今天学习python中for与while循环针对break和continue的用法

    python中有两个主要的循环for与while,其中针对这两个循环有两种不同的中断用法break与continue. 首先先看下面的循环代码: 1: for i in range(10):#变量i带 ...

  9. 开发记录_自学Python写爬虫程序爬取csdn个人博客信息

    每天刷开csdn的博客,看到一整个页面,其实对我而言,我只想看看访问量有没有上涨而已... 于是萌生了一个想法: 想写一个爬虫程序把csdn博客上边的访问量和评论数都爬下来. 打算通过网络各种搜集资料 ...

随机推荐

  1. 利用c#反射实现实体类生成以及数据获取与赋值

    转:http://hi.baidu.com/xyd21c/item/391da2fc8fb351c10dd1c8b8 原有的实体类成员逐个赋值与获取的方法弊端: 1.每次对实体类属性进行赋值时,都要检 ...

  2. 【转】匹配dll(exe)和pdb方法

    1. 静态检查windbg 调试工具包中有一个工具symchk.exe, 选项很多, 下面一个简单的用法可以检查一个 test.exe能不能找到与它匹配的PDB: 这是成功的情形. 下面来个失败的作为 ...

  3. Android桌面快捷方式那些事与那些坑

    原文来自http://blog.zanlabs.com/2015/03/14/android-shortcut-summary/ 将近二个多月没写博客了.之前一段时间一直在搞红包助手,就没抽时间写博客 ...

  4. POJ 3233 Matrix Power Serie

    题意:给一个n×n的矩阵A,求S = A + A2 + A3 + … + Ak. 解法:从式子中可得递推式S(n) = S(n - 1) + An,An = An-1×A,可得矩阵递推式 [S(n), ...

  5. lightoj 1023

    题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...

  6. hdu1896 bjfu1268 水题

    很简单的模拟,我是用的优先队列.不多说,上代码(这是bjfuoj的,hdu的要稍改一下): /* * Author : ben */ #include <cstdio> #include ...

  7. 关于jQuery中,animate、slide、fade等动画的连续触发、滞后反复执行的bug的个人解决办法

    照例,现在开头讲个这个问题发生的背景吧: 因为最近要做个操作选项的呼出,然后就想到了用默认隐藏,鼠标划过的时候显示的方法. 刚开始打算添加一个class="active",直接触发 ...

  8. Android中Cursor(游标)类的概念和用法

    使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生,如果你是搞.net 开发你大可以把Cursor理解成 Ado.net 中的数据集合相当于dataReader.今天特地将它单独拿出来谈, ...

  9. POJ 1003 解题报告

    1.问题描述: http://poj.org/problem?id=1003 2.解题思路: 最直观的的想法是看能不能够直接求出一个通项式,然后直接算就好了, 但是这样好水的样子,而且也不知道这个通项 ...

  10. java集合框架复习(一)

    数组类Array是java中最基本的一个存储结构,它用于存储 一组连续的对象或一组类型相同的基本类型的数据. Array特点:效率高,但容量固定且无法动态改变, 缺点:无法判断其中存有多少元素,len ...