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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:41:31+00:00 2026-06-07T07:41:31+00:00

I want to run a python script on ios. I don’t want to write

  • 0

I want to run a python script on ios.
I don’t want to write the whole Application in Python just a little part of it.

I have tried to understand PyObjC but it is not that easy.

Could you give me an example, please? I would like to save the result for the following method in a NSString variable.

def doSomething():
   someInfos = "test"
   return someInfos
  • 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-07T07:41:33+00:00Added an answer on June 7, 2026 at 7:41 am

    Here is an example of calling a function defined in myModule. The equivient python would be:

    import myModule
    pValue = myModule.doSomething()
    print pValue
    

    In Objective-c:

    #include <Python.h>
    
    - (void)example {
    
        PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
        NSString *nsString;
    
        // Initialize the Python Interpreter
        Py_Initialize();
    
        // Build the name object
        pName = PyString_FromString("myModule");
    
        // Load the module object
        pModule = PyImport_Import(pName);
    
        // pDict is a borrowed reference 
        pDict = PyModule_GetDict(pModule);
    
        // pFunc is also a borrowed reference 
        pFunc = PyDict_GetItemString(pDict, "doSomething");
    
        if (PyCallable_Check(pFunc)) {
            pValue = PyObject_CallObject(pFunc, NULL);
            if (pValue != NULL) {
                if (PyObject_IsInstance(pValue, (PyObject *)&PyUnicode_Type)) {
                        nsString = [NSString stringWithCharacters:((PyUnicodeObject *)pValue)->str length:((PyUnicodeObject *) pValue)->length];
                } else if (PyObject_IsInstance(pValue, (PyObject *)&PyBytes_Type)) {
                        nsString = [NSString stringWithUTF8String:((PyBytesObject *)pValue)->ob_sval];
                } else {
                        /* Handle a return value that is neither a PyUnicode_Type nor a PyBytes_Type */
                }
                Py_XDECREF(pValue);
            } else {
                PyErr_Print();
            }
        } else {
            PyErr_Print();
        }
    
        // Clean up
        Py_XDECREF(pModule);
        Py_XDECREF(pName);
    
        // Finish the Python Interpreter
        Py_Finalize();
    
        NSLog(@"%@", nsString);
    }
    

    For much more documentation check out: Extending and Embedding the Python Interpreter

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

Sidebar

Related Questions

I have a Iron Python script that I want to run and then have
I have a python script that I want always to run in the background.
If I write program in python 2.7 and I want to run another script
I have Python script bgservice.py and I want it to run all the time,
I have created a Python script that I want to run daily via a
I have a python script that i want to run from the command line
I want to run javascript/Python/Ruby inside my application. I have an application that creates
I want to run a python script from within another. By within I mean
I want to set up a cron job to run a python script, but
I want to run some Python unit tests from my Maven module. I have

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.