Python:AttributeError:' module'对象没有属性

时间:2015-05-13 07:07:30

标签: python swig

我用swig从c创建一个python文件。我已将c文件转换为.py文件,当我尝试调用c程序的函数时,我收到错误 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 个答案:

答案 0 :(得分:2)

您必须在 example.i 内嵌您的声明:

%module example
%inline %{

来自[SWIG]: Inlined code blocks

  

%inline 指令将所有跟随文字的代码插入到接口文件的标题部分。

相关问题