Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .py and .pyc files? [duplicate]

Tags:

python

file

People also ask

What is the difference between .py and PYC files?

. py files contain the source code of a program. Whereas, . pyc file contains the bytecode of your program.

Are PYC files faster than py files?

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.

What is a .PYC file in Python?

pyc files are created by the Python interpreter when a . py file is imported. They contain the "compiled bytecode" of the imported module/program so that the "translation" from source code to bytecode (which only needs to be done once) can be skipped on subsequent imports if the . pyc is newer than the corresponding .

Is it possible to decompile a compiled .PYC file into a .py file?

Yes, it is possible.


.pyc contain the compiled bytecode of Python source files. The Python interpreter loads .pyc files before .py files, so if they're present, it can save some time by not having to re-compile the Python source code. You can get rid of them if you want, but they don't cause problems, they're not big, and they may save some time when running programs.


Python compiles the .py and saves files as .pyc so it can reference them in subsequent invocations.

There's no harm in deleting them, but they will save compilation time if you're doing lots of processing.


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

http://docs.python.org/release/1.5.1p1/tut/node43.html