【发布时间】:2015-10-16 15:52:14
【问题描述】:
我已阅读 http://www.swig.org/Doc1.3/Library.html#Library_nn12 并且在 Python 中使用以下形式的函数时遇到问题:
/* foo.h */
//fills *filename with useful stuff in the usual way
int foo(char *filename);
我有一个界面文件大致如下:
%module foo
{% #include "foo.h" %}
%include "foo.h"
%cstring_bounded_output(char *filename, 1024);
extern int foo(char *filename);
swig 文档让我相信我可以不带参数地从 python 调用 foo() 并且返回值将是 python 字符串文件名。然而:
In [4]: foo.foo()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-db4ddc3a33ec> in <module>()
----> 1 foo.foo()
TypeError: foo() takes exactly 1 argument (0 given)
foo() 仍然期待一个 char *。我的接口文件是否正确?这是从这种类型的 C 函数在 python 中获取值的首选方法吗?
http://web.mit.edu/svn/src/swig-1.3.25/Lib/python/cstring.i 很难解析。如果有人知道这个宏在做什么,最好能对它有所了解。
注意:如果相关的话,我被困在使用 Swig 1.3.z 的生产环境中。此外,我必须在这里使用 Swig。
【问题讨论】: