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

The Archive Base Latest Questions

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

I have a SWIG generated function as follows: SWIGINTERN PyObject *_wrap_StrVector___getitem____SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args)

  • 0

I have a SWIG generated function as follows:

SWIGINTERN PyObject *_wrap_StrVector___getitem____SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  std::vector< std::string > *arg1 = (std::vector< std::string > *) 0 ;
  PySliceObject *arg2 = (PySliceObject *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  PyObject * obj0 = 0 ;
  PyObject * obj1 = 0 ;
  std::vector< std::string,std::allocator< std::string > > *result = 0 ;

  if (!PyArg_ParseTuple(args,(char *)"OO:StrVector___getitem__",&obj0,&obj1)) SWIG_fail;
  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_std__vectorT_std__string_std__allocatorT_std__string_t_t, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "StrVector___getitem__" "', argument " "1"" of type '" "std::vector< std::string > *""'"); 
  }
  arg1 = reinterpret_cast< std::vector< std::string > * >(argp1);
  {
    if (!PySlice_Check(obj1)) {
      SWIG_exception_fail(SWIG_ArgError(SWIG_TypeError), "in method '" "StrVector___getitem__" "', argument " "2"" of type '" "PySliceObject *""'");
    }
    arg2 = (PySliceObject *) obj1;
  }
  try {
    result = (std::vector< std::string,std::allocator< std::string > > *)std_vector_Sl_std_string_Sg____getitem____SWIG_0(arg1,arg2);
  }
  catch(std::out_of_range &_e) {
    SWIG_exception_fail(SWIG_IndexError, (&_e)->what());
  }

  *****1*****
  ***//I want to modify or print variable result here like printf("%s", result->c_str());***

  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_std__vectorT_std__string_std__allocatorT_std__string_t_t, 0 |  0 );
  return resultobj;
fail:
  return NULL;
}

I need to print the variable result at position 1(as mentioned in the code). Typemap(argout) doesn’t seem to be f much help here.

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

    I’m assuming here that the function you want to modify is a std::vector<std::string>‘s __getitem__ routine in Python.

    The easiest and safest way to modify or intercept the result of the returned value is actually to do it on the Python side, using %feature("pythonappend"), e.g.:

    %module test
    
    %{
    #include "test.h"
    %}
    
    %include "pyabc.i"
    %include "std_vector.i"
    %include "std_string.i"
    
    %feature("pythonappend") std::vector<std::string>::__getitem__ %{
      # do something
      print val
    %}
    
    %include "test.h"
    
    %template (StringVector) std::vector<std::string>;
    

    The reason this is the easiest way of modifying the result is that the next easiest way of modifying the result requires altering the typemap for the return type – in this case std::string. To do that you’d end up altering the existing std::string typemap, which gets somewhat messy.

    Alternatively you may wish to use the %exception directive to put some C++ code after $action, but unless this is for the purposes of validating the returned result it feels quite hackish.

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

Sidebar

Related Questions

I used SWIG to wrap my c++ class. Some methods have a const std::string&
I have a python module that imports a module generated with swig. When I
I have digging through the C# code generated by SWIG for Quantlib and came
I have a C function that I want to call using Java via SWIG
I have a sub in perl (generated automatically by SWIG) that I want to
I used SWIG to generate a Perl module for a C++ program. I have
OK so I have a C++ class that is exposed to Lua using SWIG.
First, I have never used SWIG, I dont know what it does... We have
I have the following code wrapped by swig: int cluster::myController(controller*& _controller) { _controller =
Has anybody out there used the SWIG library with C#? If you have, what

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.