3 ms·
Neat. Was able to clone the repo, run cargo run, and drop into a python shell. Doesn't seem like can do much right now, but I really like the idea. >>>>> a =
by lykr0n 8y ago
Neat. Was able to clone the repo, run cargo run, and drop into a python shell. Doesn't seem like can do much right now, but I really like the idea.
>>>>> a = [1,2,3]
>>>>> a[2:]
[3]
>>>>> a[1:]
[2, 3]
>>>>> fh = open('~/.ssh/id_rsa.pub', 'r')
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: RefCell { value: [PyObj instance] }', src/libcore/result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
What would be really cool if this could one day be like Nuitka- but in rust. Write in python, compile into Rust. Maybe even support inline Rust like cPython supports inline C.
- Ralfp 8y ago> cPython supports inline C First time I am hearing this. Can you share an example?
- lykr0n 8y agohttps://cffi.readthedocs.io/en/latest/ https://cffi.readthedocs.io/en/latest/ & https://docs.python.org/3/extending/extending.html https://docs.python.org/3/extending/extending.html There also is https://github.com/rochacbruno/rust-python-example https://github.com/rochacbruno/rust-python-example which is something I want to look into. As for an example, I'm using Snappy right now, so here you go: https://github.com/andrix/python-snappy/blob/master/snappy/snappy_cffi_builder.py https://github.com/andrix/python-snappy/blob/master/snappy/s... & https://github.com/andrix/python-snappy/blob/master/snappy/snappy_cffi.py https://github.com/andrix/python-snappy/blob/master/snappy/s... It still requires you to compile the C part- which is why sometimes you need GCC when you're doing a pip install.
- stochastic_monk 8y agoI’ve done a lot of interfacing with C and C++. pybind11 [0] has been the easiest and most effective for me to use. It targets C++, but it’s easy enough to wrap C code with it. Cython brings along a lot more bookkeeping code and overhead in my experience. cffi isn’t bad, but it’s not as flexible/expressive. [0] https://github.com/pybind/pybind11 https://github.com/pybind/pybind11
- filmor 8y agoCFFI has the huge advantage that you don't need to link against libpython, which in turn allows you to have a single wheel for multiple Python versions.
- half-kh-hacker 8y agoCython supports inline C, CPython does not. Maybe GP got confused?
- ciupicri 8y agoWhile your code was valid, open('~/.ssh/id_rsa.pub'...) won't work on any Python other interpreter, you need to expand ~ from the path. For example you can use: open(os.path.expanduser('~/.ssh/id_rsa.pub'), 'r')
- rmdashrfstar 8y agoDoes this line not cause the above stacktrace?