我是一名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