python bytecode questions.

W

warhero

First question, I can't seem to get any python bytecode to be
produced. I've tried different techniques from chapter 30.8 to chapter
31 of the python guide.. I was under the assumption that after
compiling a file, it would output a pyc file, but where does it go?
Any help would be appreciated.

Second, Are there any other projects out for bundling python bytecode
files, making it able to use a couple files to distribute an entire
app?? I saw one of the effbot site but it's old as it was written for
1.4..

Third, can distributing code in pyc files, speed up the application?
Or would speed increases only be seen upon application initialization?
As an example, let's say I'm running an application server, would
distributing the source in some pyc files with a bootstrapper be any
faster overall, or just on init??

Thanks
 
D

Duncan Booth

warhero said:
First question, I can't seem to get any python bytecode to be
produced. I've tried different techniques from chapter 30.8 to chapter
31 of the python guide.. I was under the assumption that after
compiling a file, it would output a pyc file, but where does it go?
Any help would be appreciated.

Any time you import a python file it will be compiled (if it hasn't already
been compiled) and a .pyc file will be generated in the same directory as
the source file (so long as you can write a file to that directory).

N.B. This only happens when you import a module: when you run a .py file as
a script it is still compiled, but no .pyc is output. If this worries you
then write a very short .py file which just imports the main program
module and calls some startup function.
Second, Are there any other projects out for bundling python bytecode
files, making it able to use a couple files to distribute an entire
app?? I saw one of the effbot site but it's old as it was written for
1.4..

For Windows you can make standalone executables with py2exe
(http://www.py2exe.org/)

More generally, assuming that Python is already installed, the trend seems
to be for packaging your code as a Python egg
(http://peak.telecommunity.com/DevCenter/PythonEggs).
Third, can distributing code in pyc files, speed up the application?
Or would speed increases only be seen upon application initialization?
As an example, let's say I'm running an application server, would
distributing the source in some pyc files with a bootstrapper be any
faster overall, or just on init??
No, the only gain is that you save the initial compile.
 
K

Kay Schluehr

First question, I can't seem to get any python bytecode to be
produced. I've tried different techniques from chapter 30.8 to chapter
31 of the python guide.. I was under the assumption that after
compiling a file, it would output a pyc file, but where does it go?
Any help would be appreciated.

You might take a look at the source of lib/compiler/pycodegen.py
Second, Are there any other projects out for bundling python bytecode
files, making it able to use a couple files to distribute an entire
app?? I saw one of the effbot site but it's old as it was written for
1.4..

Not sure what you are after. Do you want something lile PyInstaller

http://pyinstaller.python-hosting.com/

or eggs as in setuptools?

http://peak.telecommunity.com/DevCenter/setuptools
Third, can distributing code in pyc files, speed up the application?
Or would speed increases only be seen upon application initialization?
As an example, let's say I'm running an application server, would
distributing the source in some pyc files with a bootstrapper be any
faster overall, or just on init??

Thanks

The compilation overhead is neglectable. Unless you change the source
again the server will load the *.pyc file anyway. No significant
speedup has to be expected by not delivering the source.
 

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
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top