[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

How to port Python code into C++ code automatically?

xiebopublic

3/13/2008 3:16:00 AM

I want to port a Python project (about 10,000 line python code) to C+
+. Is there any automatically tool to do this kind of things? e.g.,
SWIG(http://www...)?

Any comment is welcome!

Thanks!
3 Answers

Paddy

3/13/2008 5:18:00 AM

0

On Mar 13, 3:15 am, Bo <xiebopub...@gmail.com> wrote:
> I want to port a Python project (about 10,000 line python code) to C+
> +. Is there any automatically tool to do this kind of things? e.g.,
> SWIG(http://www...)?
>
> Any comment is welcome!
>
> Thanks!

There isn't a magic porting tool available.
If you said more about the why and the resources available then you
might get a better answer.

- Paddy.

Jeff Schwab

3/13/2008 5:45:00 AM

0

Bo wrote:
> I want to port a Python project (about 10,000 line python code) to C+
> +. Is there any automatically tool to do this kind of things? e.g.,

That's not trivial. Python is very heavily oriented toward run-time
processing, whereas C++ favors compile-time processing.

> e.g., SWIG(http://www...)?

Swig isn't so much a translator as a way of linking C or C++ code to
multiple different scripting languages, using shared configuration (.i)
files. If you're only connecting two languages (Python and C++), Swig
is probably not going to help you much unless you happen to already be a
master of Swig-foo.

If the Python code works, then it's probably best to keep it in Python.
To access it from C++, try Boost.Python. If you really do need to
translate the code from Python to C++, try to do it incrementally. If
the Python code is so monolithic that you can't find individual pieces
to move one-at-a-time, consider refactoring the code in Python so that
you'll at least have some modularity to work with. (In the process of
refactoring, you may also find that you don't have to move the code out
of Python, after all, e.g. because the performance improves along with
the design.)

Marc 'BlackJack' Rintsch

3/13/2008 8:06:00 AM

0

On Wed, 12 Mar 2008 20:15:32 -0700, Bo wrote:

> I want to port a Python project (about 10,000 line python code) to C+
> +. Is there any automatically tool to do this kind of things? e.g.,
> SWIG(http://www...)?
>
> Any comment is welcome!

Have a look at the ShedSkin Python-to-C++ compiler:

http://shed-skin.blo...

It has some restrictions, i.e. the code has to be written in a more or
less statically typed way.

And me too is interested in why you want to port the entire project instead
just the time critical parts? ShedSkin might help here too. As Cython_
or Pyrex_ do. Both compile a subset of Python with optional static typing
to C extension modules.

... _Cython: http://www.c...
... _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/pyt...

Ciao,
Marc 'BlackJack' Rintsch