[Tutor] Passing a value into an embedded python interpreter

BELSEY, Dylan dylan.belsey@baesystems.com
Wed, 9 Oct 2002 11:19:48 +0930


	FYI. To answer my own question and for anyone else who is
interested....the simple solution is to use sprintf() and create a command
string, with the variable I want to pass in, as a parameter in the string.
	Then use PyRun_SimpleString(command_string) to pass it into the
interpreter.  The command string looks something like: "Python_variable =
45675218" (arbitrary number used here).
	PyRun_SimpleString lives in Python.h.  I can't claim ownership of
this solution.  It was adapted from an example in Chapter 17, Embedding and
Extending Python with C/C++, page 639, Professional Linux Programming - Neil
Matthew and Richard Stones et al., Wrox Press Ltd, 2000.
	

-----Original Message-----
From: BELSEY, Dylan [mailto:dylan.belsey@baesystems.com]
Sent: Tuesday, 8 October 2002 17:08
To: 'tutor@python.org'
Subject: [Tutor] Passing a value into an embedded python interpreter


Hi Tutor list,
	I am attempting to embed the python interpreter into C++ code.  I
have successfully been able to create functions in C++ that can be called
from the embedded interpreted environment (with the use of SWIG).  However,
I can't see my way clearly on how I can pass (map) the value of a variable
in C++, to a variable in the python namespace.
	If anyone has dealt with this or has any ideas, your advice would be
much appreciated.  I have of course been perusing the doco on extending and
embedding Python and the initial possibilities on how to tackle this problem
seem to be quite convoluted (to me anyway).
	TIA,
		Dylan

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor