After some digging in the documentation I've found that the sys.flags
struct sequence (http://docs.python.org/dev/library/sys#sys.flags) that has an optimize
attribute containing the information I was searching for.
python -c "import sys; print sys.flags.optimize"
-> 0
python -O -c "import sys; print sys.flags.optimize"
-> 1
python -OO -c "import sys; print sys.flags.optimize"
-> 2