[C++-sig] Embending : Expose and Extract a dictionary object To/From C++
Mark Chandler
admin at lodle.net
Thu Sep 3 09:22:47 CEST 2009
when you do the exec add the main_namespace twice
> object ignored = exec("print('Headline')\n print(iptc['Headline'])
> \n", main_namespace,main_namespace);
On 03/09/2009, at 3:12 PM, Constant Dupuis wrote:
> Hi,
>
> 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 {
>
> Py_Initialize();
>
> 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"
> "print(iptc['Headline'])\n",
> main_namespace);
>
>
> } catch( error_already_set ) {
> PyErr_Print();
> }
>
> And here is hte output :
>
> Hello, World!
> Headline
> Traceback (most recent call last):
> File "<string>", line 2, in <module>
> TypeError: 'NoneType' object is unsubscriptable
>
> What did I missed ?
>
> Thanks en regards,
>
> Constant
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
More information about the Cplusplus-sig
mailing list