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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:31:22+00:00 2026-06-04T14:31:22+00:00

I am searching a very small and simple sample to load a python module

  • 0

I am searching a very small and simple sample to load a python module in C app. everywhere i search I see long example and I am not understand. If this is duplicate share stackoverflow link and I will delete this question. Thank you and i am new to Python.

  • 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-04T14:31:24+00:00Added an answer on June 4, 2026 at 2:31 pm

    Create a Python Module name reverse.py as below:

    def rstring(s):
        i = len(s)-1
        t = ''
        while(i > -1):
        t += s[i]
        i -= 1
        return t
    

    Create a C application as below:

    #include <Python.h>
    int main()
    {
        PyObject *strret, *mymod, *strfunc, *strargs;
        char *cstrret;
        Py_Initialize();
        PySys_SetPath("."); 
        mymod = PyImport_ImportModule("reverse");
        strfunc = PyObject_GetAttrString(mymod, "rstring");
        strargs = Py_BuildValue("(s)", "Hello World");
        strret = PyEval_CallObject(strfunc, strargs);
        PyArg_Parse(strret, "s", &cstrret);
        printf("Reversed string: %s\n", cstrret);
        Py_Finalize();
        return 0;
    }
    

    Now be sure to keep the reverse.py and your C application in the same folder. After that please compile and run C Sample Application.

    Please study the each line in above sample, as there are about 20 total lines and if you have question about any line please let me know, I would be pleased to answer.

    Credit goes to the SO Link here as I have corrected those samples: Embedding Python into C – importing modules

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

Sidebar

Related Questions

I'm making a small Python program, which calls the webbrowser module to open a
Wrote a small app that accesses a bunch of search websites and puts the
When first searching the web for a simple CakePHP way to convert small news
I'm not very familiar with C design patterns and searching for the best solution
Ive recently started using CodeIgniter as I was searching for a very lightweight framework
This is quite possibly a very stupid question but I've tried searching for and
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
Searching a Python dictionary based on the value first, to get a key output
I'm searching for fast key-value\structured storage for lots of long strings. I'll update them
I am curious to find out what people think, we have a very small

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.