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 7075567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:11:34+00:00 2026-05-28T06:11:34+00:00

I have searched on the web and didn’t get success. I’m wrapping the sample

  • 0

I have searched on the web and didn’t get success. I’m wrapping the sample code below to Python (using SWIG):

class atomo {
public:
    int i;
    atomo(int a) {
        i = a;
    };      
};

class funa {
public:
    atomo *lista[3];

    funa() {
        lista[0] = new atomo(1);
        lista[1] = new atomo(2);
        lista[2] = new atomo(3);
    };
};

But Python can’t iterate over or access lista using the comands

>>> test = myModule.funa()
>>> test.lista[0]
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in __iter__
      TypeError: 'SwigPyObject' object is not subscriptable

>>> for i in test.lista:
>>>     print(i)
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in __iter__
      TypeError: 'SwigPyObject' object is not subscriptable

How can I make lista iterable? There is a way to use Python lists instead of C++ arrays?

My Python version is 3.2 and I’m using SWIG 2.0.4 with g++ 4.6.1

Thanks

  • 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-28T06:11:35+00:00Added an answer on May 28, 2026 at 6:11 am

    It’s a little unclear from your question if you want to use std::vector or an array of your own types.

    For std::vector, given some C++ like:

    #include <vector>
    #include <string>
    
    struct foo {
      std::string name;
    };
    
    inline std::vector<foo> test() {
      std::vector<foo> ret;
      foo instance;
      instance.name = "one";
      ret.push_back(instance);
      instance.name = "two";
      ret.push_back(instance);
      return ret;
    }
    

    You can wrap it with %template, pyabc.i and std_vector.i e.g.:

    %module test
    
    %{
    #include "test.h"
    %}
    
    %include "pyabc.i"
    %include "std_vector.i"
    
    %include "test.h"
    
    %template (FooVector) std::vector<foo>;
    

    which will behave intuitively on the Python type. You’ll need to call SWIG with something like:

    swig -python -c++ -py3 -extranative test.i

    If the idea is to wrap a “custom” container to behave intuitively on the Python side I gave a detailed example in a previous answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to translate an object without using glTranslate(). I have searched through web
Okay, I have literally searched all over the web, but I didn't find what
I searched across the web but I didn't find any satisfying answer. I have
I have searched this question but didn't get / or understood the answer I
I have searched the web and have found no definitive solution, so here goes:
I have searched the web but I cannot find the solution to my problem.
I want to install rsync on windows xp. I have searched the web, but
Windows Forms, VB. I have searched the web for the correct answer to this
I have searched on the web for software that batch convert image at different
I have searched all over the web with no luck of making this project

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.