python转cython,使用用Cython像Python到C转换器

I am EE not so familiar with Python culture and new to it.My question is regarding using Cython for converting Python to C.

Background :

I have huge python modules(+8000 lines) .They basically have tons of functions for interacting

with a hardware platform via serial port by reading and writing to hardware registers.They are not numerical algorithms. So application is just reading/writing to hardware registers/memory.

I use these libraries to write custom scripts.Eventually, I need to move all these stuff to be run in an embedded processor on my hardware to have finer control,then I just kick off the event from PC and the rest is in hardware.So I need to convert them to C.If I can have my scripts be converted to C by an automatic tool, that would save me a huge time. This is why I got attracted to Cython. Efficiency is not important my codes are not number crunchers. But generated code should be relatively small to fit in my limited memory.(few hundreds of Kilobytes)

Question :

1- Can I use Cython as converter for my custom python scripts to C ? My guess is yes.

2- Can I use these .c files to be run in my hardware ? My guess is not since I have to have Cython in my hardware as well for them to run.But if just creates some .c files , I can go through and make it standalone since code is not using much of features of Python it just use it as a fast to implement script.

解决方案Yes, at its core this is what Cython does. But ...

You don't need Cython, however, you do need libpython. You may feel like it doesn't use that many Python features, but I think if you try this you'll find it's not true -- you won't be able to separate your program from its dependence on libpython while still using the Python language.

Another option is PyPy, specifically it's translation toolchain, NOT the PyPy Python interpreter. It lets you translate RPython, a subset of the Python language, into C. If you really aren't using many Python language features or libraries, this may work.

PyPy is mostly known as an alternative Python implementation, but it is also a set of tools for compiling dynamic languages into various forms. This is what allows the PyPy implementation of Python, written in (R)Python, to be compiled to machine code.

If C++ is available, Nuitka is a Python to C++ compiler that works for regular Python, not just RPython (which is what shedskin and PyPy use).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值