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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:56:47+00:00 2026-05-23T10:56:47+00:00

I have a python function with this signature: def post_message(self, message, *args, **kwargs): I

  • 0

I have a python function with this signature:

def post_message(self, message, *args, **kwargs):

I would like to call the function from c++ and pass to it some kwargs. Calling the function is not the problem. Knowing how to pass the kwargs is. Here is a non-working paraphrased sample:

std::string message("aMessage");
boost::python::list arguments;
arguments.append("1");

boost::python::dict options;
options["source"] = "cpp";

boost::python::object python_func = get_python_func_of_wrapped_object()
python_func(message, arguments, options)

When I exercise this code, in pdb I get (which is not what I would like):

messsage = aMessage
args = (['1'], {'source': 'cpp'})
kwargs = {}

How do you pass the options in my example in the **kwargs dictionary ?

I have seen one post suggesting to use the **options syntax (how cool is this!):

python_func(message, arguments, **options)

Unfortunately, this results in

TypeError: No to_python (by-value) converter found for C++ type: class boost::python::detail::kwds_proxy

Thank you for any help you can give.

  • 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-23T10:56:48+00:00Added an answer on May 23, 2026 at 10:56 am

    After some investigation, it turns out that the object function call operator is overridden for two arguments of type args_proxy and kwds_proxy. So you have to use this specific call style of two arguments.

    args_proxy and kwds_proxy are generated by the * overloads. This is really nice.

    Additionally, the first argument must be a tuple type so that the python interpreter correctly handles the *args argument.

    The resulting example works:

    boost::python::list arguments;
    arguments.append("aMessage");
    arguments.append("1");
    
    boost::python::dict options;
    options["source"] = "cpp";
    
    boost::python::object python_func = get_python_func_of_wrapped_object()
    python_func(*boost::python::tuple(arguments), **options)
    

    Hope this helps…

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

Sidebar

Related Questions

Suppose I have this function signature: def foo(a=True, b=True, c=True, d=True, e=True): I've decided
Does anyone know how to convert this function from Python to PHP? I have
I would like to have a python function that given the list mystrings =
I have a python function that makes a subprocess call to a shell script
Say I have a Python function that returns multiple values in a tuple: def
Does python have a function like call_user_func() in PHP? PHP Version: call_user_func(array($object,$methodName),$parameters) How do
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have a python function defined as follows which i use to delete from
I am trying to figure out how to call a Python function from a
I have a python function that scrapes some data from a few different websites

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.