Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:29:57+00:00 2026-06-14T16:29:57+00:00

I am passing a list of (mostly) floats to a module in boost python,

  • 0

I am passing a list of (mostly) floats to a module in boost python, some elements are None objects. In the C++ code I am extracting the floats like so:

for(i=0;i<boost::python::len(list) - window_len + 1;i++) {
  double value = boost::python::extract<double>(list[i]);
}

This is obviously problematic when list[i] points to a python None object. As such I wrote something like this:

for(i=0;i<boost::python::len(list) - window_len + 1;i++) {
  if(list[i] == NULL) continue;
  double value = boost::python::extract<double>(list[i]);
}

and

for(i=0;i<boost::python::len(list) - window_len + 1;i++) {
  if(list[i] == boost::python::api::object()) continue;
  double value = boost::python::extract<double>(list[i]);
}

because apparently boost::python::api::object() evaluates to None. However, neither of these work. How can I check that list[i] in a python None object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:29:59+00:00Added an answer on June 14, 2026 at 4:29 pm

    Your last approach, comparing against boost::python::api::object() should work. However, it only checks if the element it actually None. The extraction can still fail if the value is neither None nor a numeric type (a string for example).

    You should use check() to ensure that the conversion was successful (if it fails, the module will throw an exception if you use the value anyway):

    for( size_t i=0, len=boost::python::len(list); i<len; ++i ) {
        boost::python::extract<double> value(list[i]);
        if( !value.check() ) continue; // check if the conversion was successful
        double d = value; // now you can use value as double
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using a BaseAdapter and passing to it a List of objects that have
I am passing a list to a view. My array looks like this: [football,
It looks like passing a list's enumerator to a function byval is quite different
I'm having a problem passing an list of application-defined objects to RIA services. I
I am facing issue in looping in the following code,i am passing a list
I am passing a list to my scala page and I have a form
I am passing a generic list to a function , i want to enumerate
Can you create a list of functions and then execute them sequentially, perhaps passing
I'm passing a List to an MVC view and generating checkboxes for each object
Is there a simple way of passing a list as the parameter to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.