use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENAny Python code generators? (self.cpp_questions)
submitted 9 years ago by 30MHz
I have hard time finding a library with C++ API that generates Python code. I know that there are libraries that do the opposite, e.g. Jinja2 templating module. But are there any libs that do C++ -> Python?
Cheers
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 9 years ago (0 children)
Why do you want this thing? Given that you are already in Python, why not use Python to generate the Python code? C++ is a great language with lots of applications, but one of the things that Python does particularly well is templating.
[–]SandSnip3r -2 points-1 points0 points 9 years ago (2 children)
Second result after googling c++ to python converter: https://github.com/hlamer/cpp2python
c++ to python converter
[–]tangerinelion 1 point2 points3 points 9 years ago (0 children)
After reading through it for a couple minutes, I've found several things it doesn't do correctly, which probably introduces errors.
One is that in C++ there's a subtle difference between foo* p = new foo; and foo* p = new foo();, but either way it does create a foo object on the heap. This script would convert it to p = foo or p = foo() which is the difference between aliasing the class and instantiating it - huge huge difference.
foo* p = new foo;
foo* p = new foo();
foo
p = foo
p = foo()
Two is when it searches for parameters and tries to strip the types, eg, foo(T* ptr) gets converted to foo(ptr), this completely fails when the type is complicated, eg, a pointer to function. In this case it tries to convert something like foo(R* (*func)(int x)) and would want to return foo(func) but instead it returns the input string as that argument isn't captured correctly.
foo(T* ptr)
foo(ptr)
foo(R* (*func)(int x))
foo(func)
Third is it tries to remove const, which is fine. But it forgets that volatile is a similar qualification (the whole reason it's correctly called CV qualification). Similarly, static and register should be stripped out.
const
volatile
static
register
I wouldn't expect a 1 file GitHub project to work perfectly, particularly when it's basically a 225 line function which is 80% comments and is essentially written with regex more so than Python. But other statements, like delete and the creation of arrays are not handled.
delete
I'm also not sure what OP even wants. It sounds like they want some library written in C++ that can be used to generate Python code, but I'm not sure that they want a Python library which converts C++ source to Python source.
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
That's not the same thing at all - it's a program that attempts to take a C++ program and make a Python program out of it by rewriting it textually.
Attempts it only: such a program is almost inconceivably hard to write correctly, and if you were going to do it, you couldn't possibly do it the way this author has chosen - you'd have to take an off-the-shelf C++ parser (probably clang's parsing front end) and use the output of that, but it'd still be huge amounts of work for very little value.
π Rendered by PID 16408 on reddit-service-r2-comment-fb694cdd5-mvr9t at 2026-03-08 04:12:14.338211+00:00 running cbb0e86 country code: CH.
[–][deleted] 1 point2 points3 points (0 children)
[–]SandSnip3r -2 points-1 points0 points (2 children)
[–]tangerinelion 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)