CXX and Python Embedding

jjwinkelman at my-deja.com jjwinkelman at my-deja.com
Fri Oct 27 11:59:08 EDT 2000


I have two questions regarding using CXX that
maybe someone can help me with.  First, let me
admit that I am new to using CXX and somewhat new
to writing extensions to Python in general.

Q1) Let's say I wanted to embed Python in a C++
app. and expose some internal objects for use by
python.  Let's also say that I create these
objects using CXX... so in C++, I have something
that looks like this:

// Example C++ code
Float f(0.0);

my variable f is now an instance of the CXX Float
class, and effectively is a PyObject*.

Now, what is the easiest way for me to expose
this to the python interpreter...

I know that I could write an extension, but what
if all I want to do was use this variable
directly from Python without importing via an
extension...

Is there any way to add this to the __main__
module as a global variable?

Q2) I have been learning how to create an
extension using CXX, and the examples show how to
add methods to my extension module via the
add_varargs_method call.... how do I add a global
variable to my extension?  Do I have to create a
method to return the variable I wish to expose?

Thanks for you help in advance.

Jeff.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list