HN2new | past | comments | ask | show | jobs | submitlogin
A framework for creating Python/C++ polyglots (github.com/wmww)
110 points by mnem on March 7, 2019 | hide | past | favorite | 14 comments


For anyone looking for a more usable version of C++/Python interop, I can't recommend Cppyy[0] highly enough. You can use any C++ code/libraries from Python without the need to write any bindings. I created an example project here to test it out[1].

0. https://cppyy.readthedocs.io/en/latest/

1. https://github.com/jclay/cppyy-knearestneighbors-example


From your second link:

" Note: I'm using Python 2

This is because even the latest clang-python in Debian (for clang 6) provides Python 2 bindings only. "

Is this still true?


I believe it's no longer the case. The maintainer of Cppyy was cautioning that the Python 3 support was somewhat experimental at the time, but I believe it's officially supported now. Either way, it could have been solved by building from source, but I was feeling lazy :)


I was just wondering if there was something like Rcpp but for Python, looks like this is it. Thanks for sharing



Looks a lot like what you can do with PyROOT... oh it's even based on cling.


Wow


> The exact same Python++ file can be fed in unmodified to a stock C++ compiler and a stock Python interpreter and you will get the same output. The first version of Python++ was developed by William W Wold for the Stupid Shit No One Needs and Terrible Ideas Hackathon 2017.

Sounds about right, but it is very impressive.


Came here for this. At least they are self aware.


Impressive and hilarious.


This is really clever! Here's a more traditional approach that I stumbled across:

https://github.com/lukasmartinelli/py14

It translates a small subset of Python to C++ 14.

I'm going to attempt this for real pretty soon on my shell project :) Although I'm using MyPy rather than relying on type inference.

MyPy is useful and solid now!


If anyone seriously want to write a program that works equally in Python and C++, use Haxe, which compiles to a few more targets as well: JavaScript, Java, C#, C (HashLink), Lua etc.

Haxe isn't a polyglot, but a compiled language though.


All I really want is a minimum effort way to map C++ libraries to Python in a way that supports Numpy and is not tied to a Python version. CFFI is close, but it could be even more ergonomic. Build scripts can generate everything else automatically, outside Numpy functions.


I like Pybind.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: