Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to port Python code into C++ code automatically?

Reply
Thread Tools

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

 
 
Bo
Guest
Posts: n/a
 
      03-13-2008
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.swig.org/)?

Any comment is welcome!

Thanks!
 
Reply With Quote
 
 
 
 
Paddy
Guest
Posts: n/a
 
      03-13-2008
On Mar 13, 3:15 am, Bo <(E-Mail Removed)> 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.swig.org/)?
>
> 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.
 
Reply With Quote
 
 
 
 
Jeff Schwab
Guest
Posts: n/a
 
      03-13-2008
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.org/)?


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.)
 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      03-13-2008
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.swig.org/)?
>
> Any comment is welcome!


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

http://shed-skin.blogspot.com/

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.cython.org/
... _Pyrex: http://www.cosc.canterbury.ac.nz/gre.../python/Pyrex/

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Overhead of 4-port over 2-port SRAM John T. Goodman VHDL 0 01-25-2005 04:27 PM
Port-security on 16-port FastEthernet module (NM-ESW-16) Dmitry Cisco 0 04-01-2004 06:38 PM
Port security on a Catalyst 4000 - fails to shut down port Jon Whitear Cisco 2 11-04-2003 11:01 PM
about "match ip rtp starting-port-number port-range" Weiguang Shi Cisco 1 10-25-2003 07:14 AM



Advertisments