embedding, PyString_FromString

Brian Quinlan brian at sweetapp.com
Sun Dec 15 17:21:36 EST 2002


> I guess the default namespace, __main__, isn't sufficient for my task.
> Mark Lutz says that it's not straightforward to communicate inputs and
> outputs with the Python code using PyRun_SimpleString.

I'm not sure that you understand Martin's point: Python doesn't know
anything about pstr1. Imagine that you are doing this in C:

void main()
{
	char * foo = "bar";

	print_var("foo"); /* should print "bar" */
}

How would you implement print_var? 

You couldn't, of course, because print_var has no way of knowing about
the "foo" identifier, just as Python has no way of knowing about the
"pstr1" identifier.

You have to figure out what module you want to add pstr1 to. It's
probably best to create a new module (not __main__) and stick all your
crap in there. You can then use PyModule_AddObject to add pstr1 to that
module.

Cheers,
Brian





More information about the Python-list mailing list