[C++-sig] instantiating python objects within C++

Stefan Seefeld seefeld at sympatico.ca
Fri May 23 21:56:22 CEST 2003


Hi Adam,

Adam Hupp wrote:

> Try looking at libs/python/test/embedding.cpp.  It has a nice example
> of this usage.  

thanks for the pointer. I looked, but the main question is still
unanswered, as the example instantiates an object 'implemented' in
python (derived from a C++ type). Do I really have to run the
interpreter to instantiate a python-wrapper-object around my own type ?

Anyways, I tried and failed. I attach the test, may be someone can
see what I'm doing wrong...

Running the compiled program (which calls 'script.py') results in
the following output:

<code object ? at 0x8120068, file "null", line 1>
<type 'code'>
python exception
Traceback (most recent call last):
   File "script.py", line 3, in ?
     object.value = 42
TypeError: 'code' object has only read-only attributes (assign to .value)


Thanks a lot,
		Stefan
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Embedded.cc
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030523/bb1aff74/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: script.py
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030523/bb1aff74/attachment-0001.txt>


More information about the Cplusplus-sig mailing list