Generating .pyo from .py

S

skn

Hello.,

Does the python compiler provide an option to generate a .pyo(optimized byte
code file) from a .py (source file)?

For generating .pyc I know that I only have to pass the source file name as
an argument to py_compile.py.
But for generating .pyo, I could not find anything.

Any clues/help will be greatly appreciated.

With best regards,
skn
 
M

Maurice LING

say your code is "test.py" and you usually run it as "python test.py",
then the "-O" option will generate .pyo files.
That is "python -O test.py"

Cheers maurice
 
L

Leif K-Brooks

skn said:
Does the python compiler provide an option to generate a .pyo(optimized byte
code file) from a .py (source file)?

For generating .pyc I know that I only have to pass the source file name as
an argument to py_compile.py.

py_compile.py checks __debug__ to decide whether to use optimize mode,
and the -O option to Python turns __debug__ off, so:

python -O py_compile.py foo.py
 
S

skn

Thanks a lot !!
It works fine !!

regards,
skn

Leif K-Brooks said:
py_compile.py checks __debug__ to decide whether to use optimize mode,
and the -O option to Python turns __debug__ off, so:

python -O py_compile.py foo.py
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top