Can .py be complied?

Filip Dreger fdreger at amiga.pl
Wed Apr 27 06:53:18 EDT 2005


U¿ytkownik "monkey" <m at m.com> napisa³ w wiadomo¶ci 
news:426f562f$1_3 at rain.i-cable.com...

> If using Jython to complie, is the end-user need JRE instead of 
> Python
> installed, or need both of them?

Only JRE. Just like Java.

>> I don't know the exact details, but try using the compiled Python
>> scripts (bytecode). I believe they are semi-optimized and platform
>> independent. They are the .pyc and .pyo files generated when the 
>> script
>> is run.
> Is that means a .py convert to .pyc or .pyo, without the need of 
> "make file"
> as using py2exe?

.pyc files are generated every time a module (any .py file can be a 
module) is imported. So if you have a program, say, example.py, you 
just start the python interpreter and write:
>>> import example
And then example.pyc will appear beside example.py. This new file does 
not require example.py (you can even delete it), and works on any 
computer with Python installed (on Windows you can just double-click 
it)
If you start the Python interpreter using:
python -OO (if you are using Windows, you shoud start the interpreter 
from the command line, probably something like:
c:
cd \
python24\python -OO)
and then import your example.py, you will get a file example.pyo, 
which is also stripped of any documentation strings (a bit harder to 
decode).

regards,
Filip Dreger 





More information about the Python-list mailing list