[C++-sig] Embending : Expose and Extract a dictionary object To/From C++

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Sep 3 19:04:42 CEST 2009

Hi, I'm not sure this is relevant (sorry, no time to look closely), but a couple weeks ago
I fixed a bug in exec.cpp:

r55639 | rwgk | 2009-08-17 17:24:54 -0700 (Mon, 17 Aug 2009) | 8 lines

libs/python/src/exec.cpp: bug fixes
  operator!() for boost::python::object invokes PyObject_IsTrue()
  and is therefore not equivalent to "is None".
  In this particular case !global or !local returns true for an
  empty dict.
(Changes to libs/python/test/exec.cpp just helped in debugging.)


This made it into the 1.40.0 release. I recommend you work with the current trunk or
the latest release.


----- Original Message ----
From: Constant Dupuis <constant.dupuis at gmail.com>
To: cplusplus-sig at python.org
Sent: Thursday, September 3, 2009 12:12:07 AM
Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++


I would like to expose a dictionary object instanciated in C++ to a
Python code, which manipulate the dictoinary.
And after extract the resulting modified dictionary back in C++.

I try this :

try {


    std::cout << "Hello, World!\n";
    dict d;
    d["Headline"] = "Titre";
    object main_module = import("__main__");
    object main_namespace = main_module.attr("__dict__");

    main_namespace["iptc"] = ptr(&d);
    object ignored = exec("print('Headline')\n"

} catch( error_already_set ) {

And here is hte output :

Hello, World!
Traceback (most recent call last):
  File "<string>", line 2, in <module>
TypeError: 'NoneType' object is unsubscriptable

What did I missed ?

Thanks en regards,

Cplusplus-sig mailing list
Cplusplus-sig at python.org

More information about the Cplusplus-sig mailing list