c调用python参数_Python与C参数交互

C

参数交互

(

结构指针

).

2007-11-04 17:54 991

人阅读

评论

(0)

收藏

举报

Python

中某些时候需要

C

做效率上的补充

.

在实际应用中

,

需要做部分数据的交互

.

Python

可以通用

ctypes

模块很好地调用

C.

下面演示了

Python

中调用

C

一个标准函数

.

传递一个结构指针入

.

得到

C

中分配内存数据

传递出

.

希望对你的

Python

学习有所帮助

.

1 test.c

#include

#include

typedef

struct

{

unsigned

char

words[10];

} keywords;

typedef

struct

{

keywords *kws;

unsigned

int

len;

} outStruct;

int

test(outStruct *o){

unsigned

int

i=4;

o->kws = (keywords *)malloc(

sizeof

(unsigned

char

)*10*i);

strcpy(o->kws[0].words,"test 1");

strcpy(o->kws[1].words,"test 2");

o->len = i;

return

1;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值