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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:30:38+00:00 2026-06-07T18:30:38+00:00

I have a Python module written in C with a number of functions exposed.

  • 0

I have a Python module written in C with a number of functions exposed. One of them has a Python definition of:

def SetPowerSupply(voltage, current, supply):

where voltage = float, current = float, and supply = int. On the C side, I have this:

float voltage, current;
int supply;

if (!PyArg_ParseTuple(args, "ffi", &voltage, &current, &supply))
{
    // Failed to parse
    // ...
}

One of my scripters has a script wherein this function fails to parse the arguments, complaining that an integer is expected. So far as I can tell, an integer is in fact being passed in since if in the error branch I do this:

PyObject *num = PyNumber_Float(PyTuple_GetItem(args, 0));
voltage = PyFloat_AsDouble(num);
Py_XDECREF(num);

num = PyNumber_Float(PyTuple_GetItem(args, 1));
current = PyFloat_AsDouble(num);
Py_XDECREF(num);

num = PyNumber_Int(PyTuple_GetItem(args, 2));
supply = PyLong_AsLong(num);
Py_XDECREF(num);

… then everything works as expected. Other script running through this module do not exhibit this behaviour, and I can see no differences. Both of them call the function the same:

SetPowerSupply(37.5, 0.5, 1)
SetPowerSupply(0, 0, 1)

In the offending script I can do something like this:

Any ideas???

Thank you.


Edit:

The problem was caused by another function which was being called several calls prior to this function. It was:

if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
{
    // Parsing the pin as an int failed, try as a string
    if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
    {
        // ...

The purpose of this was to basically overload the third argument to accept either a string or numerical value. When someone fed a string to it, the Python error from the failed parse was never cleared. Updated code resolving the issue follows.

if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
{
    PyErr_Clear();

    // Parsing the pin as an int failed, try as a string
    if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
    {
        // ...

Many thanks to Ignacio for the clue.

  • 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-06-07T18:30:41+00:00Added an answer on June 7, 2026 at 6:30 pm

    One of your other functions is failing to return None when appropriate, and you’re catching this error message by accident.

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

Sidebar

Related Questions

Basically I have written two modules for my Python Program. I need one module
I have written a Python module which contains functions that return arrays. I want
I have written a Python module, and I have two versions: a pure Python
I have Python extension module written in C. I want to use in this
I have some python module, which has a class ModuleClass and I can't modify
I have a python module written in C, and I would like to add
I have written a Python module including a submodule written in C: the module
I have written a module in python which performs some function. I then created
I have written a Python module that I'd like to make available for others.
I have a program written in python using the module networkx to create a

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.