2015-05-13 75 views
1

我用swig從c創建一個python文件。我已經將c文件轉換爲.py文件,當我嘗試調用c程序的函數時,出現錯誤 AttributeError:'模塊'對象沒有屬性'fact'Python:AttributeError:'模塊'對象沒有屬性

我的C文件是

/* File : example.c */ 


#include <time.h> 
double My_variable = 3.0; 

int fact(int n) { 
    if (n <= 1) return 1; 
    else return n*fact(n-1); 
} 

int my_mod(int x, int y) { 
    return (x%y); 
} 

char *get_time() 
{ 
    time_t ltime; 
    time(&ltime); 
    return ctime(&ltime); 
} 

我的接口文件是

/* example.i */ 
%module example 
%{ 
/* Put header files here or function declarations like below */ 
extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 
%} 

有人能幫助我嗎?

回答

1

你必須直列您在example.i聲明:

%module example 
%inline %{ 

[SWIG]: Inlined code blocks

The %inline directive inserts all of the code that follows verbatim into the header portion of an interface file.

相關問題