使用用Cython像Python到C转换器 [英] Use Cython as Python to C Converter

查看:1086
本文介绍了使用用Cython像Python到C转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不EE那么熟悉Python的文化和新it.My问题用用Cython为Python转换到C是关于


背景:

我有巨大的Python模块(+8000线)。他们基本上有大量的功能交互
通过串行端口硬件平台通过读取和写入到硬件registers.They不是数值算法。因此,应用程序只是读/写硬件寄存器/内存。
我使用这些库编写自定义scripts.Eventually,我需要将所有这些东西将在嵌入式处理器上我的硬件上运行有更好的控制,那么我刚刚从PC揭开序幕的事件,其余是hardware.So我需要将它们转换为C.如果我可以有我的剧本由自动工具转换为C,这将节省我大量的时间。这就是为什么我被吸引到用Cython。效率并不重要我的codeS不是数字打交道。但产生code应该是比较小,适合在我的有限的内存。(几百几千字节)


问:

1 - 我可以用用Cython作为转换器,用于我的自定义Python脚本到C?我的猜测是肯定的。

2 - 我能否使用这些.c文件在我的硬件上运行?我的猜测是不是因为我必须用Cython在我的硬件,以及为他们run.But如果只是创建了一些.c文件,我可以顺利通过,并使其独立,因为code没有使用太多的Python的功能它只是把它作为一种快速实现脚本。


解决方案

  1. 是在其核心,这是用Cython做什么。但是......

  2. 您不需要用Cython,但是,你确实需要 libpython 。你可能觉得它不使用Python的许多功能,但我想如果你试试这个,你会发现这不是真的 - 你将无法在你的程序从依赖分离libpython 同时仍使用Python语言。

另一种选择是 PyPy 时,特别是翻译工具链不会的PyPy的Python间preTER。它可以让你翻译 RPython ,Python语言的一个子集,到C.如果你真的不使用许多Python语言的特性或库,这可能工作。

PyPy大多称为替代Python实现,但它也是用于编译动态语言成各种形式的一组工具。这就是让PyPy Python实现,写在(R)的Python,被编译成机器code。

如果C ++是可用的, Nuitka 是一个Python和C ++编译器,对于常规的Python,而不仅仅是RPython(这是shedskin和PyPy使用)。

工作

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.

解决方案

  1. Yes, at its core this is what Cython does. But ...
  2. 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).

这篇关于使用用Cython像Python到C转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆