swig & Python question

It's me itsme at yahoo.com
Thu Dec 9 01:53:08 EST 2004


I am playing around with SWING building a Python module using the no brainer
example in http://www.swig.org/tutorial.html.   With that first example,


/* 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);
 }
and using the swig file of:
/* example.i */
 %module example
 %{
 /* Put header files here (optional) */
 %}

 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
I was able to execute this Python script:


>>> import example
 >>> example.fact(5)
 120
 >>> example.my_mod(7,3)
 1
 >>> example.get_time()
 'Sun Feb 11 23:01:07 1996'
 >>>
However, when I try to access the gloabl variable My_variable by doing:

    print example.cvar

I get a blank (rather then a value of 3.0).

Why?

--
It's me





More information about the Python-list mailing list