簡體   English   中英

Python:AttributeError:“模塊”對象沒有屬性

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

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

我的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();
 %}

有人可以幫我嗎?

您必須在example.i中 內聯聲明:

%module example
%inline %{

來自[SWIG]:內聯代碼塊

%inline指令將逐字后面的所有代碼插入接口文件的頭部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM