帮助创建C函数的扩展 [英] Help creating extension for C function

查看:48
本文介绍了帮助创建C函数的扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为C函数编写一个扩展名,以便我可以从python中调用它来获得



C代码(myapp.c)< br $>
======

typedef unsigned long MY_LONG;


char * DoStuff(char * input,MY_LONG * x) {...}


所以你传入一个字符串和一个MY_LONGS数组......比如


MY_LONGS vals [10] = {....};

char * input ="这是我的输入" ;;

char * result;


result = DoStuff(输入,vals);


....我需要创建一个扩展名,这样我就可以用Python调用它了

这样的as ...

I need to write an extension for a C function so that I can call it
from python.

C code (myapp.c)
======
typedef unsigned long MY_LONG;

char *DoStuff(char *input, MY_LONG *x) { ... }

so you pass in a string and an array of MY_LONGS...such as

MY_LONGS vals[10] = {....};
char *input = "this is my input";
char *result;

result = DoStuff(input, vals);

....I need to create an extension so that I can call this from Python
such as...

import myapp
vals = [1,2,3,4,5,6,7,8,9 ,10]
输入=这是我的输入
结果= myapp.DoStuff(输入,vals)
打印结果
import myapp
vals = [1,2,3,4,5,6,7,8,9,10]
input = "this is my input"
result = myapp.DoStuff(input, vals)
print result




理想情况下,结果将是一个字符串,vals将是一个列表并输入

将是一个字符串。


我希望跟随如何编写扩展,如图所示

这里 http://docs.python.org/ext/contents.html


....但更好的例子会有所帮助。


谢谢。



ideally the result would be a String, vals would be a list and input
would be a string.

I was hoping to follow along with how to write an extension, as shown
here http://docs.python.org/ext/contents.html.

....but a better example would help.

Thanks.

推荐答案

" Java and Swing"写道:
"Java and Swing" wrote:
我需要为C函数编写一个扩展名,以便我可以从python中调用它。

C代码(myapp。 c)
======
typedef unsigned long MY_LONG;

char * DoStuff(char * input,MY_LONG * x){...}

所以你传入一个字符串和一个MY_LONGS数组......比如

MY_LONGS vals [10] = {....};
char * input =" ;这是我的输入" ;;
char *结果;

结果= DoStuff(输入,vals);

...我需要创建一个扩展所以我可以用Python来调用它
如...
I need to write an extension for a C function so that I can call it
from python.

C code (myapp.c)
======
typedef unsigned long MY_LONG;

char *DoStuff(char *input, MY_LONG *x) { ... }

so you pass in a string and an array of MY_LONGS...such as

MY_LONGS vals[10] = {....};
char *input = "this is my input";
char *result;

result = DoStuff(input, vals);

...I need to create an extension so that I can call this from Python
such as...
import myapp
vals = [1,2,3 ,4,5,6,7,8,9,10]
input ="这是我的输入"
结果= myapp.DoStuff(输入,vals)
打印结果将是一个字符串。
import myapp
vals = [1,2,3,4,5,6,7,8,9,10]
input = "this is my input"
result = myapp.DoStuff(input, vals)
print result
ideally the result would be a String, vals would be a list and input
would be a string.






更多module.c


/ *
more module.c

/*


Id


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

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