简体   繁体   English

Python:AttributeError:“模块”对象没有属性

[英]Python: AttributeError: 'module' object has no attribute

I used swig to create a python file from c. 我用swig从c创建一个python文件。 I have converted the c file into .py file and when I try to invoke a function of the c program, I am getting an error AttributeError: 'module' object has no attribute 'fact' 我已将c文件转换为.py文件,当我尝试调用c程序的函数时,出现错误AttributeError:'module'对象没有属性'fact'

My C file is 我的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);
 }

My interface file is 我的界面文件是

   /* 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();
 %}

can somebody help me? 有人可以帮我吗?

You have to inline your declarations in example.i : 您必须在example.i中 内联声明:

%module example
%inline %{

From [SWIG]: Inlined code blocks : 来自[SWIG]:内联代码块

The %inline directive inserts all of the code that follows verbatim into the header portion of an interface file. %inline指令将逐字后面的所有代码插入接口文件的头部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:AttributeError:&#39;module&#39;对象没有属性&#39;socketpair&#39; - Python: AttributeError: 'module' object has no attribute 'socketpair' Python AttributeError:“模块”对象没有属性“获取” - Python AttributeError: 'module' object has no attribute 'get' python - AttributeError:&#39;module&#39;对象没有属性&#39;lock&#39; - python - AttributeError: 'module' object has no attribute 'lock' Python错误:AttributeError:&#39;module&#39;对象没有属性 - Python error: AttributeError: 'module' object has no attribute Python AttributeError:“模块”对象没有属性“ Goslate” - Python AttributeError: 'module' object has no attribute 'Goslate' Python:AttributeError:“模块”对象没有属性“ randrange” - Python: AttributeError: 'module' object has no attribute 'randrange' python - AttributeError:&#39;module&#39;对象没有属性 - python - AttributeError: 'module' object has no attribute Python-AttributeError:“模块”对象没有属性“ QueryFrame” - Python - AttributeError: 'module' object has no attribute 'QueryFrame' python:AttributeError,“模块”对象没有属性“某物” - python: AttributeError, 'module' object has no attribute 'something' AttributeError:&#39;module&#39;对象没有属性&#39;subscribe&#39;Python - AttributeError: 'module' object has no attribute 'subscribe' Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM