Newbie has problem changing C char strings with Python/SWIG

Rick Olson r_olson at
Fri Jan 9 04:05:04 CET 2004

I've tried posting this on the SWIG listserve, but traffic has been
slow there and I haven't had a reply.  If this isn't the correct
forum, please suggest another.  Thanks.

I'm trying to use python as the interface for an existing program
written in C.  I've gotten many things to work including using cvar to
assign values to long and double variables in the C module from
python. I'm having trouble using it to assign strings.  I've reduced
the problem to the following .c and .i files, and a sample idlefork
char *eval_name;
void define_globals()
{ eval_name = "Bob";
%module example
extern void define_globals();
extern char *eval_name;
IDLEfork 0.9b1      
>>> import example
>>> example.define_globals()
>>> example.cvar.eval_name
>>> example.cvar.eval_name='Tony'
>>> ==== RESTART ================================

I seem to be able to use Python invoke the C function that assigns
"Bob" to the variable eval_name, but when I try to assign a new name
('Tony') the idlefork shell restarts.

I've combed the docs and the archives at, but I didn't see
this  ddressed anywhere.  I strongly suspect that I looked right at
it, but didn't
recognize it at the time.  This leads to 2 questions:

1) How do I perofrm the desired assignment?
2) Where was the answer in the docs so I can look at it and try to
understand how I overlooked it.

Thanks in advance--
Rick Olson

More information about the Python-list mailing list