Currently on calling one of the compileall functions it is not possible to pass the optimization level as argument. The bytecode will be created depending of the optimization level of the current script instance. But if a script wants to compile .pyc files for one destination and .pyo files for another destination this will be a little tricky.
Hi. Since Python 3.2, compileall functions supports the optimization level through the `optimize` parameter. I guess you are using Python2.7 or so? Also, there's a note in compileall's documentation regarding the command line switch for the optimization level: " There is no command-line option to control the optimization level used by the compile() function, because the Python interpreter itself already provides the option: python -O -m compileall. " http://docs.python.org/3.2/library/compileall.html#command-line-use
> Hi. Since Python 3.2, compileall functions supports the optimization level through the `optimize` parameter. > There is no command-line option to control the optimization level used by the compile() function, because the Python interpreter itself already provides the option: python -O -m compileall. This is the problem: You can't pass the optimization level to compile_dir|compile_file
compile_path. What, if you want for location a .pyc files and for location b .pyo files? Or even .pyc files and .pyo files for both locations? The only solution is to make a command call within the script which is a little bit ugly.
If I understand correctly, compileall is intended as a command-line tool, but there is py_compile if you want programmatic access. Does py_compile provide functions that let you control the optimization level?