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.

Hidding the Console

As you have probably noticed the typical Python extension is .py.  If you change this in explorer to .pyw pythonw.exe will execute the script instead of python.exe.  As a result the console window will be suppressed and any GUI windows will still come up.  Preventing the console looks more professional for a finished build, but during development it is still very useful for debugging.

.py appication launches a shell.