Compiling a Python File on Mac OS X Tiger


A

Asad Habib

Hello. I am working on Tiger and wanted to find out how to compile a
Python (.py) file into a .pyc file and then into a .pyo file. Can the
compilation be achieved within the interpreter? Also, I am
new to Python and wanted to know the difference between .pyc and .pyo
files. Is this comparison similar to C? Any help would be appreciated.
Thanks.

- Asad
 
Ad

Advertisements

J

Jacob Page

Asad said:
Hello. I am working on Tiger and wanted to find out how to compile a
Python (.py) file into a .pyc file and then into a .pyo file. Can the
compilation be achieved within the interpreter? Also, I am
new to Python and wanted to know the difference between .pyc and .pyo
files. Is this comparison similar to C? Any help would be appreciated.
Thanks.

http://www.network-theory.co.uk/docs/pytut/tut_48.html has some good
explanations. To generate the .pyo files from the interpreter, add the
-O option.

The difference between .pyc and .pyo files is that .pyo files are
optimized a bit; for example docstrings are removed (which will break
pydoc tests). According to the above link, .pyo files don't run any
faster; they just load faster.
 

Top