Python frontend to C++ code

Donn Cave donn at oz.net
Sun Sep 3 00:55:02 EDT 2000


Quoth s_gherman at yahoo.com:
| Hi. I've read in many places that Python is ideal for fast prototyping
| and for building a portable frontend to C/C++ code.
|
| I am a Python beginner but an experimented C++ programmer and I am
| considering building such a frontend. But I am not sure which are my
| options: I've read about embeding and extending Python (but both seem
| to request quite a lot of wrapping code, which doesn't sound to me
| like "fast prototyping").
|
| So, I'd like to ask you guys which are my options in this case?

I think you're looking at them -- Python gets access to new functions
by embedding or extending with the kind of C wrapper code you have
been reading about.

If you have a lot of C interface to account for, that will be a lot
of work, probably too much unless you can at least partially automate
it with something like SWIG.  C++ could add some difficulty too, it's
ironically really awkward to get some of the OO aspects of C++ across
the C/Python interface.

But as a programming problem, this phase is fairly analytical.
I mean, you sit there with the manual and nail that interface down
in gory detail, as much as you can bear.  Especially, you verify
all the return values and raise an exception for any problem that
seems to warrant it, and you allocate and free storage as needed.

That's what makes Python a fast prototyping language.  The modules
people have built for Python are like the roads the Romans built
through Europe.  On this solid ground, you can move fast as you
work on aspects of program design that aren't so analytical -
user interface, multi-threaded event dispatching models, all kinds
of things that can be done a lot of different ways and are hard to
get right the first time through.

On a completely different note, you may after all be able to get
to C/C++ functions without any wrappers, if they support an external
dispatch protocol - I don't know what I'm talking about here, but
someone with more MS background might be able to advise you about
COM and Python and whether that would be practical for what you're
doing.  Or similar notions for whatever platform you're using.

	Donn Cave, donn at oz.net



More information about the Python-list mailing list