Python和C. [英] Python and C

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

问题描述

我曾经是一名C程序员。最近开始在学校学习一个小项目的学习。我加入了一家小公司,在那里他们使用

C ++进行开发。


我们可以一起使用Python和C吗?我的意思是用Python创建一些类

和用C编写的一些数字运算算法(速度)和

将它们都集成在一起。


有人可以只展示一个真实的小例子或指示

一样。


谢谢

解决方案

di ******** @ gmail.com 写道:

我曾经是一名C程序员。最近开始学习Python for
在学校的一个小项目。我加入了一家小公司,在那里他们使用C ++进行开发。

我们可以一起使用Python和C吗?我的意思是用Python创建一些类和一些用C语言编写的数字运算算法(用于速度)和
集成两者。

有人可以展示一个真正的小例子或者指向
同样。




文档中甚至还有一整节用于 -

和破坏实际阅读它的乐趣:是的,Python和C go aleong

_very_好,对于C ++,有几个专门的包装生成器

,例如让PyQt绕道而行。查看SIP或boost.python或SWIG。

http://docs.python.org/api/api.html


Diez


> http://docs.python.org/api/api.html

应该是

http://docs.python.org/ext/ext.html


但迟早需要另一个。


Diez


< di ******** @ gmail.com>写道:

我曾经是一名C程序员。最近开始学习Python for
在学校的一个小项目。我加入了一家小公司,在那里他们使用C ++进行开发。

我们可以一起使用Python和C吗?我的意思是用Python创建一些类和一些用C语言编写的数字运算算法(用于速度)和
集成两者。


当然可以!这是非常普遍的做法,被称为扩展Python。


可能有人只是展示一个真实的小例子或指向
同样的。



除了扩展/嵌入和C API文档,它们是

的一部分,是标准的Python文档集,你已经指向了它在

其他回复中,您可以在网上找到教程。一个小小的是

< http://www.developer.com/lang/other/article.php/2191421> ;,其他材料的指示

。此外,示例可以在Python源代码发布的Demos目录中找到 - 即使你有一个二进制发行版

,也可以获得源发行版,它是'充满好吃的你和你好b $ b可以用很多Python本身作为扩展的例子(模块

和源发行版的Objects目录,特别是,只是

这样的例子)。


C是最低,最基本的扩展级别,但有很多

其他替代方案 - - SWIG用于包装现有库,Boost或SCXX或

SIP以特定的方式包装C ++,具有非常不同的理念(模板

重,最小,基于Qt),pyrex(a Python方言加上类似C的

声明,使其可以编辑快速机器代码),还有其他人

尚未。

Alex


I was a C Programmer for a while. Lately started to learn Python for
one small project at school. I joined a small company where they use
C++ for development.

Can we use Python and C together ? I mean create some classes in Python
and some number crunching algorithms coded in C (for speed) and
integreate both of them.

Could somebody just show a real small example or give pointers to the
same.

Thanks

解决方案

di********@gmail.com wrote:

I was a C Programmer for a while. Lately started to learn Python for
one small project at school. I joined a small company where they use
C++ for development.

Can we use Python and C together ? I mean create some classes in Python
and some number crunching algorithms coded in C (for speed) and
integreate both of them.

Could somebody just show a real small example or give pointers to the
same.



There is even a whole section in the documentation geared towards that -
and to spoil the fun of actually reading it: Yes, Python and C go aleong
_very_ well, and for C++ there are several specialized wrapping generators
that e.g. make PyQt go round. Check out SIP or boost.python or SWIG.

http://docs.python.org/api/api.html

Diez


> http://docs.python.org/api/api.html
That should have been

http://docs.python.org/ext/ext.html

but you need the other one sooner or later.

Diez


<di********@gmail.com> wrote:

I was a C Programmer for a while. Lately started to learn Python for
one small project at school. I joined a small company where they use
C++ for development.

Can we use Python and C together ? I mean create some classes in Python
and some number crunching algorithms coded in C (for speed) and
integreate both of them.
Sure! It''s extremely common practice, known as "extending Python".

Could somebody just show a real small example or give pointers to the
same.



Besides the Extending/Embedding and C API documents which are part of
the standard set of Python docs, to which you''ve already been pointed in
other responses, you can find tutorials on the net. A tiny one is at
<http://www.developer.com/lang/other/article.php/2191421>, with pointers
to other materials. Also, examples can be found in the Demos directory
of the Python source distribution -- even if you have a binary distro
installed, get the source distro anyway, it''s full of goodies and you
can use much of Python itself as an example of Extending (the Modules
and Objects directories of the source distro, in particular, are just
such examples).

C is the lowest, most fundamental level of extension, but there are many
other alternatives -- SWIG to wrap existing libraries, Boost or SCXX or
SIP to wrap specifically C++ with very different philosophies (template
heavy, minimal, Qt-based), pyrex (a Python "dialect" plus C-like
declarations to make it compilable to fast machine code), and others
yet.
Alex


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

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