Saturday, January 1, 2011

Other Extensions

If you've looked into the Python install dir you've most likely seen .pyc and .pyo files. Unlike .pyw files which are simply renamed extension, .pyc and .pyo are encoded by the interpreter and are no longer human readable.  Typically compiled python (.pyc) are created by the interpreter once a .py file is run.  However, if the option was turned off during installation the following can create them for you. -O and -OO flags will optimize the code further.
python -m py_compile myFile.py
python -m compileall -l .
Although it would be nice to get a speed boost from optimizing and compiling our code that is not the case.  You may find a minor improvement in the launch time, since the interpreter no longer needs to convert it to bytecode, but the main advantage is to have some code protection if you are distributing your program.