[C++-sig] Re: compile errors with embedding example from tutorial

Faheem Mitha faheem at email.unc.edu
Thu Jul 1 22:34:49 CEST 2004


On Thu, 01 Jul 2004 12:50:45 -0400, David Abrahams
<dave at boost-consulting.com> wrote:

> Graeme Lufkin <graeme.lufkin at gmail.com> writes:
>
>>     I've had similar problems, and have slogged my way to figuring
>> them out.  The tutorial is wrong, at least on gcc 3.2.3.
>
> I think the tutorial is right in CVS.  Have you checked that?
>
> http://www.boost-consulting.com/boost/libs/python/
>
>>   Here's what you want:  After calling Py_Initialize(), you should get
>> the Python main namespace object by doing:
>>
>> handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
>> dict main_namespace = extract<dict>(PyModule_GetDict(main_module.get()));
>
> Seems harder than neccessary.
>
> object main_module = object(handle<> (borrowed(
>                         PyImport_AddModule("__main__") )));
>
> object main_namespace = main_module.attr("__dict__");

http://www.boost-consulting.com/boost/libs/python/doc/tutorial/doc
					/using_the_interpreter.html

uses

 object main_module(
        handle<>(borrowed(PyImport_AddModule("__main__"))));

instead, which does not compile with gcc 3.3, at least for me.

In any case, as I already said, even when this compiles correctly, it
still does not seem to execute the interpreter correctly, ie. I get
the error

NameError: name 'file' is not defined

Can you suggest what might be the problem here?

                                                        Faheem.





More information about the Cplusplus-sig mailing list