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

The Archive Base Latest Questions

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

In an embedded python scenario we are using PyArg_ParseTupleAndKeywords to receive data from Python

  • 0

In an embedded python scenario we are using PyArg_ParseTupleAndKeywords to receive data from Python (version >=3 .x) and use it in a C++ application.

At the moment we have a similar setup:

PyObject* whatever(PyObject *self, PyObject *args, PyObject *keywds) {
    ....
    static char* kwlist[] = { "foo", "bar", NULL };
    ...
if(!PyArg_ParseTupleAndKeywords(args, keywds, ..., kwlist, ...))
    {
        ...bail out

however, if we pass more parameters than the two expected (e.g. issuing a python call like whatever(foo="a", bar="b", baz="c")) the whole thing crashes (not really, it returns an error, but that’s beyond the scope here).

We would like to avoid such scenarios; it would be great if we could parse only the parameters in the kwlist and ignore everthing else. What’s the best way to do it?

One solution we were thinking about was to convert kwlist into a dict, then manipulate it with PyDict_Merge or the like.

  • 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:06:27+00:00Added an answer on May 26, 2026 at 3:06 pm

    In the end we solved it like below:

    (I’m answering my own question since nobody answered, and I think it might be valuable to somebody else in the future).

    PyObject* whatever(PyObject *self, PyObject *args, PyObject *incoming_keywds) 
    {
    
        static char* kwlist[] = { "foo", "bar", NULL };
    
        PyObject* keywds = PyDict_New();
        /**
         * The following routine returns a subset of the incoming dictionary 'incoming_keywds'
         * containing only the keys allowed in the list 'kwlist'
         */
        for ( int i = 0 ; kwlist[i] != NULL ; i++ )
        {
            char* key = kwlist[i];
            PyObject *single_key = Py_BuildValue("s", key);
            if ( PyDict_Contains(incoming_keywds, single_key) )
            {
                // not checking for NULL as GetItem return value since
                // we already checked above if the dict contains key 'single_key'
                if ( PyDict_SetItem(keywds, single_key, PyDict_GetItem(incoming_keywds, single_key)) < 0 )
                {
                    /* error */
                }
            }
            Py_DECREF(single_key);
        }
        /** end */  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an old version of python on an embedded platform ( Python 1.5.2+
I'm trying to emulate code.InteractiveInterpreter from the embedded Python C API. I'm using PyEval_Evalcode
I have embedded a Python interpreter in a C program. Suppose the C program
How could I create embedded objects in an MS office document using Python? I
What is the best way to use an embedded database, say sqlite in Python:
I have an embedded python interpreter in my program. I'd like to export a
I'm thinking about using Python as an embedded scripting language in a hobby project
I'm using the SocketServer module in python to implement a simple embedded web server
I have a python program in an embedded system that needs to write to
I'm trying to add embedded python to a OpenGL/SDL application. So far everything works

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.