'C++ to simpler language (Python, Lua, etc) converter? [closed]

I know Python and I've come across a small C++ source file I would like to convert to Python. But the C++ code is too complex for me to understand without learning the language.

So I was wondering if there is a tool that does the opposite of what many people want: convert C++ code to Python, or another simpler language I could understand. I know these tools work on very simple code and hardly do a perfect job even then, but the code I have is pretty small and simple.

I have found "ctopy", but there is no usage example, if I just pass a .cpp file to it, it just hangs, no error message or anything. And maybe it won't work for C++ at all. http://www.catb.org/~esr/ctopy/



Solution 1:[1]

Most translators produce inferior code which you can't really use anywhere; and the more complicated your code is, the worse the results are. Only real human brains can do that perfectly. I'd suggest that you learn the language. If you already know python, learning another language shouldn't be too difficult.

Solution 2:[2]

I've seen (and wanted) such a programming code converter and found exactly what you want in cpp2py although I personally haven't tried it for myself website https://github.com/hlamer/cpp2python

Solution 3:[3]

It's a little painful, but I have gotten some python code using

https://code.google.com/p/ctypesgen/

For some reason it doesn't handle bool's.

It probably uses regex substitutions, and other things like that, but it sure beats writing out your own ctypes wrapper without it.

http://docs.python.org/2/library/ctypes.html

Another option you could look into, is compiling your C++ into an executable and then running the executable using python.

And if you decide you need the power of C/C++ in your tool belt:

https://stackoverflow.com/questions/3973899/learning-c-java-coming-from-python

Hope that helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Cashern
Solution 3 Community