Question

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/

Was it helpful?

Solution

Trust me, don't waste your time finding such software. Only real human brains can do that perfectly. Take my advice, learn the language. If you already know python, it won't take much time for you to learn C++. All the programming languages are brothers! You don't have to go into the depths of the language. Browse cheat-sheets, read good articles, watch videos and ask questions here. This way, you'll learn the basic things quickly and you'll have an added advantage of knowing another language.

I found a concise C++ primer here: http://www.entish.org/realquickcpp/. Good Luck! :)

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top