[C++-sig] On wrapping vector<pair<string, double> >

Zhang Le ejoy at 163.com
Thu Oct 2 05:48:59 CEST 2003


> From: Nicodemus <nicodemus at globalite.com.br>
> Subject: Re: [C++-sig] On wrapping vector<pair<string, double> >
> To: Development of Python/C++ integration <c++-sig at python.org>
> Message-ID: <3F7963B7.3030904 at globalite.com.br>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> It is hard to tell by your description of the problem alone, some code 
> would help. But try this:
> 
> py::list py_eval(py::list v)
> {
>     vector< pair<string, double> > input;
>     int i;
>     int len = py::extract<int>(v.attr("__len__")());
> ...
Thank you. I have tracked the bug:
I forget to use attr("__len__") to get the length of a list. Actually,
I'm trying to do:
     size_t len = py::extract<size_t>(v);

I have an additional question: How to detect a type of a py::object in
boost.python?

I want to change my function to accept either 'str' or 'list' type.
py_eval(py::object obj) {
   if (type(obj) is 'str') {
      ...
   } else if (type(obj) is 'list' or 'tuple') {
   ...
   }
}

How to do the above statements in c++ code?

Thanks.
-- 
                                     Sincerely yours,
                                            Zhang Le




More information about the Cplusplus-sig mailing list