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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:19:34+00:00 2026-06-14T22:19:34+00:00

I have a scenario where I have some functions in C++ classes and I

  • 0

I have a scenario where I have some functions in C++ classes and I want to be able to call them using a python script. Let’s say I have a function

void greet(_msg);
    std::cout >> _msg >> std::endl;

I want to be able to call it trough a custom Python call and pass arguments to it, for example using

saySomething("Hello")

As a .py file I want it to call the greet function and pass “Hello” as an argument.

I know it’s a subject that has been throughly discussed, and I’ve done a share of research on embedding python in C++, I’ve managed to read values from a python script using the standard Python/C API and run a function in Python from C++ and pass argument to it, but I can’t seem to get my head around how to achieve this specific outcome.

I’ve had a look at ctypes and various wrappin libraries such as boost:python or swig, but I can’t seem to understand to which degree they could help me achieve want I want.

  • 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-14T22:19:35+00:00Added an answer on June 14, 2026 at 10:19 pm

    Depending on which version of Python you are interested in, 2.x or 3.x,
    read through the Extending and Embedding the Python Interpreter chapter for 2.x or 3.x. You are interested only in extending Python, so section the 1. Extending Python with C or C++ will provide you with complete explanation how to implement what you need in order to be able to call your functions implemented in C++ from Python script.

    Certainly, there are numerous libraries and generators which allow you to wrap C/C++ APIs for Python (e.g. Boost.Python or SWIG), but your case sounds simple enough, that for the purpose of learning it is IMO better to get familiar with Python C API. Even if you use these tools, you will frequently have to get down to Python C API anyway or at least understand it.

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

Sidebar

Related Questions

I have a scenario where I have to invoke some functions using XML RPC.
Scenario :- I have to call MYSQL stored procedure from PHP and do some
Scenario: You have a reasonably sized project with some forms, classes, etc. Question: How
Let say I have a class like the following: class MyClass { public function
We have a scenario where some .NET code is attempting to access the current
I have a 'simple' scenario: Read some JSON file, Filter or change some of
Scenario: I have a view that has some DataTemplate resources <DataTemplate x:Key=myDragCueTemplate> <Border Background=Blue
Scenario I have a windows service written in C# that performs some processing based
Here is the scenario: I have a visual that displays some data The data
Skip to the specific question as needed. Some background: The scenario: I have 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.