Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert python source code to C++ source code [duplicate]

I have been trying to find a way to convert .py source file to .cpp source (as a time saver from doing it manually). I've never used python before and was hoping for a quick way to convert it, and cleanup any code the converter might not do well.

So far, some of the options that I have found while googling seem to be: nuitka, cython, and pypy/rpython.

However, the documentation I have read only seem to produce executables, and not actual source code.

At this point, I have found py2c, but cannot seem to find any documentation on how to use it. Also, judging by the posted roadmap on the wiki, it does not seem to be a finished product, and so I'm doubtful as to its reliability.

If you can provide other sources on how this can be accomplished, or shed some light on something I may have missed on the above-mentioned possibilities, it would be appreciated. Otherwise, I will simply convert it manually.

like image 265
quandrei Avatar asked Mar 08 '13 20:03

quandrei


1 Answers

Programming languages cannot be easily converted like this. For example, Python has a large standard library, C++ doesn't have the same library. How do you translate those calls?

More fundamentally, the semantics of the language are very different, even a statement as simple as x = 1 means something different in Python and C++.

You are going to have to write C++ while reading the Python.

like image 90
Ned Batchelder Avatar answered Sep 29 '22 00:09

Ned Batchelder