My C code defines a constant, I'm trying to add python code (in a pythoncode block) that uses that constant, for some reason this doesn't work.
Demonstration .i file:
%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,}
%}
Here's the error:
[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
If I comment out the lookup dictionary in the pythoncode block, everything works fine:
[dave]$ python -c "import test; print test.i"
3
so at least when I import the module the constant shows up.
How can I "see" the C-defined constants in my pythoncode block?
swig 2.0.4, python 2.7.