Doubt C and Python

michael savvyside at aol.com
Thu Aug 25 07:11:24 EDT 2005


On Tue, 23 Aug 2005 06:15:03 +0100, praba kar wrote:

> Dear All,
>    I want to know the link between c and python.
>    Some people with C background use Python instead   
> of  programming in C.why?
> 
> 
>  
> regards
> Prabahar
> 
> 
> 	
> 
> 	
> 		
Just my $.02

I am a long time c/c++ programmer (by profession). I fell in love with
python about 2 years ago. I use python for many things now, and I always
have said, "When it is too slow, I will write it in c++".

I have not hit that point yet. For some reasons that are hard to explain,
even though python "should" be slower and maybe even is sometimes, it
never is an issue. 

One reason is that python has so much better data structures built in, and
THEY are written in C, I end up with faster code. For example, if I am
doing a bunch of string compares in C, I would use a dictionary in python.
Python ends up faster because I can get to a better algorithm FASTER.

The other reason is that so many times, a hardware I/O device is really
the limiting factor (such as a hard disc, or a serial/network connection,
or waiting for the user). 

I have found that GUI programs written in python/wxpython to be every bit
as fast as pure C++. I guess you could say that because the LIBRARIES of
python are in C, and because you are never very far from a library call,
you end up running C code a large percentage of the time, even when you
are writing in Python.

My advice is to just TRY python and resolve the "slow" speed if you ever
hit it. I never have and I write a lot of code, even hardcore math and
image processing (See PIL - python Imaging Library).

Michael





More information about the Python-list mailing list