6 ms·
A framework for creating Python/C++ polyglots
- OceanKing 8y ago> 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.
- jclay 8y agoFor 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/ https://cppyy.readthedocs.io/en/latest/ 1. https://github.com/jclay/cppyy-knearestneighbors-example https://github.com/jclay/cppyy-knearestneighbors-example
- cheez 8y agoWow
- cozzyd 8y agoLooks a lot like what you can do with PyROOT... oh it's even based on cling.
- kyllo 8y agoI was just wondering if there was something like Rcpp but for Python, looks like this is it. Thanks for sharing
- mbeex 8y agoFrom 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?
- jclay 8y agoI 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 :)
- basementcat 8y agoThis reminds me of scipy weave https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/weave.html https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/w...
- chubot 8y agoThis is really clever! Here's a more traditional approach that I stumbled across: https://github.com/lukasmartinelli/py14 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!
- adamnemecek 8y agoI like Pybind.
- andyonthewings 8y agoIf 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.
- 127 8y agoAll 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.