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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:20:49+00:00 2026-06-02T07:20:49+00:00

I am using the Python/C API and would like a C function to take

  • 0

I am using the Python/C API and would like a C function to take a Python long integer argument, nPyLong, and convert it to a char array, nString, in base 10. Here is a snippet of what I would like to do.

PyObject *nPyLong;
PyArg_ParseTuple(args, "O", nPyLong);

PyLong_Check(nPyLong) // returns true

const char *nString;
// This function doesn't exist but demonstrates the functionality
PyLong_AsCharArray(&nString, nPyLong, 10);

The API reference mentions a function PyObject* PyLong_FromString(char *str, char **pend, int base) which converts a C char array to a Python long integer, given an arbitrary base, but I cannot find a function which does the inverse.

Is this possible? One idea is to convert the Python long integer to a Python string object and then convert to a C char array, but there are no string functions to handle long ints either. It seems the only way for C to handle Python long ints is to convert to C int types, all of which would overflow in my application.

  • 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-02T07:20:51+00:00Added an answer on June 2, 2026 at 7:20 am

    Use PyObject_Str() (or PyObject_Bytes()) and convert the resultant object into a char*.

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

Sidebar

Related Questions

I am using python and would like a simple api or regex to check
From the c-api, I would like to call a python function by name. I
I would like to open a new tab in my web browser using python's
I would like to create an app using python on google app engine to
I am using python and Google app engine. I would like to use the
I would really like to write tests for Google App Engine using their python
I would like to generate useful documentation for a REST API written in Python.
How should __nonzero__ be implemented using the Python C-API? The reason I'm asking is
I'm having trouble with encodings when calling the Quickbase API using Python. I call
I'm calling a web API exposed by TheyWorkForYou (TWFI). http://www.theyworkforyou.com/api/ I'm using the Python

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.