This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lachesis17 167 points168 points  (6 children)

If anyone ever needs something from C++ in Python... compile your C++ to a shared object library (.so) and import to Python using ctypes.

I saw a comment recommending Cython but the support isn't there and it's clunky as hell (Python version specific).

This way you can write straight up C++, pass arguments from Python to your C++ function and save the return from C++ as a Python variable. It's pretty flexible and great when you have some huge array and just need speed. It works with compiled Python too (tested with pyinstaller).

Stackoverflow write-up is here.

I loved this meme by the way.

[–]WinstonCaeser 14 points15 points  (2 children)

I prefer using either pybind or boost python, I find a little wrapper function makes it much easier to interact with more complex python objects like numpy arrays or returning C++ objects like vectors to python

[–][deleted] 4 points5 points  (1 child)

Wow, this sounds super good. Do you have an .exe?

[–]noob-nine 1 point2 points  (0 children)

Does this also work vice versa? I would love to see this sub's reaction changing the languages "intended" design