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

  • Home
  • SEARCH
  • 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 5984075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:19:20+00:00 2026-05-22T22:19:20+00:00

I have a method in c++ that gets called from python and needs to

  • 0

I have a method in c++ that gets called from python and needs to return a python list object.

I have already created the method, and its attached to an exposed class and callable from python right now… (it returns void).

So the question is, how do I create a python list from this:

std::vector<std::string> results;

I am not really understanding how the constructor works from this documentation:

http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/list.html

Also… I don’t really want to return kind of wrapped vector… I just want to create a new python list with the string values from the vector.

My apologies if this is a duplicate… I found quite a few list to vector questions but I couldn’t find any about creating a new python list.

I could expand this question to include some other questions like:

Creating a new python dictionary from a: std::map<std::string, std::string> and so on.

  • 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-05-22T22:19:21+00:00Added an answer on May 22, 2026 at 10:19 pm

    I have this function using iterators to convert std::vector to py::list:

    namespace py = boost::python;
    
    template<class T>
    py::list std_vector_to_py_list(const std::vector<T>& v)
    {
        py::object get_iter = py::iterator<std::vector<T> >();
        py::object iter = get_iter(v);
        py::list l(iter);
        return l;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that can return either a single object or a collection
I have some code in a controller (HomeController.cs) that gets called from a $.get
I have this method which gets called from a different class: -(void)artworkInfo:(NSNumber *)pos{ [image
I have class method that returns a list of employees that I can iterate
I have a method that needs to accept an array of country names, and
I have a method that creates a MessageDigest (a hash) from a file, and
I have a list that gets refreshed every 2 seconds via the Handler postDelayed()
I have a List that I have populated in the main method of a
I have a method that where I want to redirect the user back to
I have a method that takes an IQueryable. Is there a LINQ query that

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.