[C++-sig] Re: getting result from the interpreter -- boost-python
Benjamin Collar
collar at gamic.com
Tue Oct 14 14:50:16 CEST 2003
Hello David,
On Tuesday 14 October 2003 14:25, David Abrahams wrote:
> > does not work properly in my environment.
> ^^^^^^^^^^^^^^
> ...which is... ??
GCC 3.3.1, Python 2.3.2, Gentoo Linux.
I've reposted the example here, with line numbers in front. The line numbers
start at 32 because I cut and pasted the code from the tutorial directly into
my application, right in the middle (after some app initialization and
whatnot). The place where I got the example?
http://www.boost.org/libs/python/doc/tutorial/doc/using_the_interpreter.html
> > Here's the example:
32 handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
33 dict main_namespace(handle<>(borrowed(
PyModule_GetDict(main_module.get()) )));
34 handle<>( PyRun_String("result = 5 ** 2", Py_file_input,
35 main_namespace.ptr(), main_namespace.ptr()) );
36 int five_squared = extract<int>( main_namespace["result"] );
> > This will not compile:
> > main.cc: In function `int main(int, char**)':
> > main.cc:33: error: variable declaration is not allowed here
> > main.cc:35: error: request for member `ptr' in `main_namespace()',
> > which is of non-aggregate type `boost::python::dict ()()'
> > main.cc:35: error: request for member `ptr' in `main_namespace()',
> > which is of non-aggregate type `boost::python::dict ()()'
> > main.cc:36: error: invalid types `boost::python::dict ()()[const
> > char[7]]' for array subscript
>
> I'd write:
> [example cut]
> 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.
Me too! That's easier to understand.
I appreciate your help. The code looks a little simpler on my end now.
Thanks
Ben
--
----------------------------------------
(o__ Benjamin Collar
//\ GAMIC mbH ++49 (0)241 889 110
V_/_ Developer/System Administrator
To know recursion, you must first know recursion
More information about the Cplusplus-sig
mailing list