compiling python code

  • Thread starter Gabriele *Darkbard* Farina
  • Start date
G

Gabriele *Darkbard* Farina

Hi,

I have a python file inside a zip file. I'd like to compile it and add
the resulting .pyc file into the zip. I tryed reading the source and
compiling it using compile(), but I don't know how to write .pyc file.
Can someone give me some help?

bye,
gabriele
 
F

Fredrik Lundh

Gabriele said:
I have a python file inside a zip file. I'd like to compile it and add
the resulting .pyc file into the zip. I tryed reading the source and
compiling it using compile(), but I don't know how to write .pyc file.
Can someone give me some help?

a PYC file consists of a 4-byte header (from imp.get_magic()), an 4-byte
timestamp (seconds since epoch as a 32-bit little endian integer), followed
by the marshalled code block.

see the source code for the py_compile module in the standard library for
some sample code -- or use the module itself to do the work for you:

http://effbot.org/librarybook/py-compile.htm

</F>
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top