Home › Forums › Python Programming › .pyc files in python
- This topic has 0 replies, 1 voice, and was last updated 11 years, 10 months ago by
Humble.
-
AuthorPosts
-
Humble
Keymastermost of the time, I was asked what is “.pyc” files in my filesystem and why it exist? well, it has something to do with python.. That said, those contains “bytecodes”. byte codes for python virtual machine.. well, in other way, it make faster execution of a python program . ie The execution is made faster by loading the program fast [1]. These byte codes are used by the python virtual machine.. Inside python interpreter, a c program normally generate these byte codes and these byte code operate on objects used in your python program..
[1] Ref http://docs.python.org/release/1.5.1p1/tut/node43.html
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 possible to have a file called “spam.pyc” (or “spam.pyo” when -O is used) without a module “spam.py” in 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.
isnt it self explanatory?
-
AuthorPosts