How to translate python into C

Benjamin Niemann pink at odahoda.de
Fri Oct 28 06:08:20 EDT 2005


Johnny Lee wrote:

> Hi,
>    First, I want to know whether the python interpreter translate the
> code directly into machine code, or translate it into C then into
> machine code?

Neither this nor that. The interpreter first compiles the code into python
'byte code' - something similar to machine code, but not it is not targeted
at the CPU of your system, but for a portable virtual machine. This virtual
machine will then execute the byte code, just like a CPU would execute
machine code.

>    Second, if the codes are translated directly into machine codes, how
> can I translate the codes into C COMPLETELY the same? if the codes are
> translated first into C, where can I get the C source?

You may have a look at PyPy. I do not know what it exactly can do, but this
might be interesting for you:
http://codespeak.net/pypy/dist/pypy/doc/faq.html#how-do-i-compile-my-own-programs

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/



More information about the Python-list mailing list