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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:57:45+00:00 2026-05-26T15:57:45+00:00

Using SWIG to generate a Python interface to a C++ application, is there any

  • 0

Using SWIG to generate a Python interface to a C++ application, is there any way to have it comment the functions in the generated .py file? I’m actually pulling in an entire .h file into the .i file, but for a small example:

%module example

bool do_something_interesting(int number, string text);

swig -python example.i Generates:

...
def do_something_interesting(*args):
  return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting

Ideally, I would like it to automatically add a comment with the original method signature

#bool do_something_interesting(int number, string text)
def do_something_interesting(*args):
  return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting

But I would be perfectly amenable to writing my own comment somewhere (particularly if the comment could somehow be in the .h file). I thought %pythonprepend might be a possible solution, but it inserts code inside the function definition rather than before it.

EDIT: Here’s what I came up with in the .h file. Not the prettiest thing ever but it’ll do:

#ifdef SWIG
   %pythonprepend do_something_interesting(int, string) %{
    """Do some interesting thing

    number:Int -- a number
    text:String -- some text

    """
  %}
#endif
bool do_something_interesting(int number, string text);
  • 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-26T15:57:46+00:00Added an answer on May 26, 2026 at 3:57 pm

    Look at the docstring feature in SWIG for Python.
    Probably putting the following line in your .i file

    %feature("autodoc", "1")
    

    would do what you want (see http://www.swig.org/Doc2.0/Python.html#Python_nn65 for more options)

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

Sidebar

Related Questions

I have a cpp file with functions that I'm using in python with SWIG.
I just on internet the Google is using swig. Does any one have used
I was able to generate python bindings for a camera library using SWIG and
Anyone have any experience using SWIG ? I am currently researching QuantLib and saw
I'm wrapping a C++ library in PHP using SWIG and there have been some
Anyone have experience with using SWIG (the interface generator)? I have a C project
My application is using SWIG to communicate between c++ and python on windows. suppose
I have embedded Ruby inside my C++ application. I have generated the bindings using
I'm using SWIG to create a Python interface to my C++ class library. I
OK so I have a C++ class that is exposed to Lua using SWIG.

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.