我是一名Python初学者,我需要测试一个被引用调用的C函数。是否可以通过引用从python调用C函数?
这里是我的C文件:myfile.c文件
#include<stdio.h>
int my_function(int *x)
{
int A;
printf("enter value of A");
scanf("%d",&A);
*x = 10 * A; // this sets the value to the address x is referencing to
return 0;
}
现在, 我的Python脚本应该调用创建my_function(),并传递参数,这样我可以检查和验证结果。
类似:
result = self.loaded_class.my_function(addressOf(some_variable))
self.assertEqual(some_variable,10)
这可能吗?我怎么能做到这一点。 而我正在为Python自动测试编写脚本,而不是使用交互式python。
如何你编译你的C代码?也许你可以使用ctypes。 – HYRY 2013-03-19 13:15:22