[C++-sig] Re: getting result from the interpreter -- boost-python

Dirk Gerrits dirk at gerrits.homeip.net
Fri Oct 17 22:45:24 CEST 2003


Sorry for my slow response, hectic week...

David Abrahams wrote:
[...]
> The problem is that the line declaring "main_namespace" is declaring
> a function which returns a dict.  But where did you get that line?
> It's not in any of the docs I can find.

Oh it's there. :\ At the time, I was using MSVC7 or Intel7 I think, so 
apparently this slipped through the maze of standard non-compliance, and 
I didn't see it either. But GCC 3.3.2 on my GNU/Linux Debian 
installation indeed complains about this, and rightly so.

Sorry.

> I'd write:
>     
>     // Retrieve the main module
>     python::object main_module = python::extract<python::object>(
>         PyImport_AddModule("__main__")
>     );
>     
>     // Retrieve the main module's namespace
>     python::object main_namespace = main_module.attr("__dict__");
>     
> or, if your code has to run on broken compilers like vc6:
> 
>     // Retrieve the main module
>     python::object main_module = python::extract<python::object>(
>         PyImport_AddModule("__main__")
>     )();
>     
>     // Retrieve the main module's namespace
>     python::object main_namespace(main_module.attr("__dict__"));
> 
> In fact, I would like it very much if we could change the examples in
> the tutorial to use this style.  It's far simpler and clearer, IMO.

I concur. Fixes the bug and removes some of the nasty syntax. I'll make 
a patch and send it to you.

Joel, should I correct quickstart.txt or the HTML files generated from 
it? If the former, then I'd like the modified quickdoc you used to build 
the HTML files, to verify my changes. If the latter, what's 
quickstart.txt still doing there? :)

I'll also edit embedding.cpp, if that's okay. It's not broken, but it 
could use the same stylistic enhancements.

Dirk Gerrits






More information about the Cplusplus-sig mailing list