附:发现目前用 Rust 来扩展/优化 Python 是一种逐渐很流行的做法, hg 已经在用Rust 替代其 C 扩展来优化速度,放几条相关信息:
![]() | 1 daiyuok 2018-03-23 15:44:44 +08:00 再推荐你一个--JPype |
![]() | 2 shoaly 2018-03-23 17:44:14 +08:00 ![]() 我不小心联想到了 茴香豆的 4 种写法 |
3 yongzhong 2018-03-23 17:49:26 +08:00 ![]() 加上一种,py2 (lambda _, __, ___, ____, _____, ______, _______, ________: getattr( __import__(True.__class__.__name__[_] + [].__class__.__name__[__]), ().__class__.__eq__.__class__.__name__[:__] + ().__iter__().__class__.__name__[_____:________] )( _, (lambda _, __, ___: _(_, __, ___))( lambda _, __, ___: chr(___ % __) + _(_, __, ___ // __) if ___ else (lambda: _).func_code.co_lnotab, _ << ________, (((_____ << ____) + _) << ((___ << _____) - ___)) + (((((___ << __) - _) << ___) + _) << ((_____ << ____) + (_ << _))) + (((_______ << __) - _) << (((((_ << ___) + _)) << ___) + (_ << _))) + (((_______ << ___) + _) << ((_ << ______) + _)) + (((_______ << ____) - _) << ((_______ << ___))) + (((_ << ____) - _) << ((((___ << __) + _) << __) - _)) - (_______ << ((((___ << __) - _) << __) + _)) + (_______ << (((((_ << ___) + _)) << __))) - ((((((_ << ___) + _)) << __) + _) << ((((___ << __) + _) << _))) + (((_______ << __) - _) << (((((_ << ___) + _)) << _))) + (((___ << ___) + _) << ((_____ << _))) + (_____ << ______) + (_ << ___) ) ) )( *(lambda _, __, ___: _(_, __, ___))( (lambda _, __, ___: [__(___[(lambda: _).func_code.co_nlocals])] + _(_, __, ___[(lambda _: _).func_code.co_nlocals:]) if ___ else [] ), lambda _: _.func_code.co_argcount, ( lambda _: _, lambda _, __: _, lambda _, __, ___: _, lambda _, __, ___, ____: _, lambda _, __, ___, ____, _____: _, lambda _, __, ___, ____, _____, ______: _, lambda _, __, ___, ____, _____, ______, _______: _, lambda _, __, ___, ____, _____, ______, _______, ________: _ ) ) ) |
![]() | 4 pkookp8 2018-03-23 17:51:24 +08:00 via Android 对不起,我根本不懂 py |
![]() | 5 GoLand 2018-03-23 19:48:29 +08:00 ![]() import __hello__ 这个很少人知道吧? |
![]() | 6 assad 2018-03-23 19:58:20 +08:00 via Android ![]() Python 不是将就只用一种方法做事么? |
![]() | 7 lingo 2018-03-23 19:59:51 +08:00 有点强行了。。。 |
![]() | 8 dd99iii 2018-03-23 20:45:27 +08:00 疼 |
![]() | 10 hellolleh 2018-03-23 21:21:52 +08:00 5. ctypes 这个好像不对吧,python 里面字符串是一个 list,你这样传给 c 的函数,c 只能接受一个 h,后面的是没法传递过去的。 |
![]() | 11 risent OP @hellolleh 这个是会自动转换的 > None, integers, longs, byte strings and unicode strings are the only native Python objects that can directly be used as parameters in these function calls. None is passed as a C NULL pointer, byte strings and unicode strings are passed as pointer to the memory block that contains their data (char * or wchar_t *). Python integers and Python longs are passed as the platforms default C int type, their value is masked to fit into the C type. https://docs.python.org/2/library/ctypes.html |
![]() | 13 risent OP @assad 主要是针对不同的情况, 比如需要用到一个 C/C++ 的库,那么就可以很快的通过 ctypes 或者 cffi 的方式快速的撸一个 binding 出来, 或者如果想对某一个模块 /功能在性能上优化一下,那么可以将其直接用 Cython 或者 Rust 直接重写,然后提供给 Python 来调用。 |
![]() | 14 hellolleh 2018-03-23 21:55:36 +08:00 @risent [!ctypes_demo]( http://xray.qiniudn.com/ctypes_demo.png) |
![]() | 15 alexyangjie 2018-03-23 22:00:41 +08:00 via iPhone 也想到了茴香豆。。。。 |
![]() | 16 SingeeKing PRO @yongzhong #3 有 3 的版本吗 ![]() |
![]() | 17 risent OP |
![]() | 18 neocanable 2018-03-23 23:52:26 +08:00 @pkookp8 py 不是跑友的意思么? |
19 pwrliang 2018-03-24 09:11:46 +08:00 via Android 我觉得挺好的,收藏了,尤其是 python 调用 c 的代码 |
![]() | 21 JerseyCafe 2018-03-27 09:45:57 +08:00 666666 |
![]() | 22 est 2018-03-27 15:04:00 +08:00 最装逼的一种写法你没列出 import __hello__ |