我的C代码定义了一个常量,我试图添加使用该常量的Python代码(在pythoncode
块中),由于某些原因,这不起作用。在Python代码块中使用模块定义的常量
示范.i
文件:
%module test
%{
// c code defines a static constant
static const int i=3;
%}
// declare the constant so that it shows up in the python module
static const int i;
%pythoncode %{
# try to use the constant in some python code
lookup={'i':i,}
%}
这里的错误:
[dave]$ python -c "import test"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "test.py", line 70, in <module>
lookup={'i':i,}
NameError: name 'i' is not defined
如果我注释掉pythoncode
块lookup
字典,一切工作正常:
[dave]$ python -c "import test; print test.i"
3
所以至少当我重要时常数显示模块。
如何在我的pythoncode
块中“查看”C定义的常量?
swig 2.0.4,python 2.7。对于%pythoncode