19th October 2011

Python Reference

Variable Scoping

Scope is innermost function, class or module (not block). Assignment creates new local variable. To access a global variable, use global foo.

System Integration

Locate site package directory for all python installations:

for p in `which -a python`; do
    echo -n "$p: "
    "$p" -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Compile python code to .pyc:

#!/usr/bin/env python
import sys
import py_compile

for file in sys.argv: