Newbie: Python + C Question

laotseu bdesth at removethis.free.fr
Tue Apr 8 17:18:05 EDT 2003


bourassa wrote:
> Hi there.  I have a question about Python and the interaction with C. 
>  From Python I can use C extensions.  But does doing so speed up 
> execution speed? 

Yes, unless your C code is braindead buggy

> When Python uses the C extension does it just process 
> it in an interpreted fashion

Python is not a C interpreter.

> or does the code written in C run like a 
> compiled C program?  

newbie to programming, uh ?-)

How do you think this all works ?

the Python interpreter byte-compile and execute python source code, not 
C source code. C being a compiled language, C source code is just text, 
nothing you can execute before compilation (ie : transformation of 
source code into machine code).

When you use a "C extension" in Python, you use in fact a 
machine-language compiled extension. The 'C extension' term is faulty. 
The fact is that the extenstion has generally been written in C before 
compilation, hence the term, but  open such an extension with your 
favorite code editor, I can tell you you wont find anything like a C 
source in it !-)

BTW, Python (I mean the Python interpreter) itself is written in C.

Laotseu.





More information about the Python-list mailing list