[C++-sig] Embending : Expose and Extract a dictionary object To/From C++
Constant Dupuis
constant.dupuis at gmail.com
Thu Sep 3 09:41:36 CEST 2009
Ok, thanks,
Now I got a "Segmentation fault" error message when I try "print
iptc['Headline']".
Is the dict object directly exposable ? Or do I have to create a
std::map base class ?
Constant
2009/9/3 Mark Chandler <admin at lodle.net>:
> 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
>
> _______________________________________________
> 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