Python for ios解释器

编程入门 行业动态 更新时间:2024-10-27 16:38:48
本文介绍了Python for ios解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: iOS上的Python或Ruby解释器

我只是发现这个应用程序 pypad 和 python for ios

I just discovered this apps pypad and python for ios

他们喜欢翻译编辑

那么你会推荐哪个app

So which app would you recomend

但最重要的是,这个解释器是如何工作的,我在哪里可以看到一个如何使用obj c的例子和python开始工作togheter?

But most importantly, how does this interpreter work, and where can i see an example of how the obj c and python get to work togheter?

谢谢!

推荐答案

我我是适用于iOS的Python 的唯一创建者,所以这当然是我推荐的,但是个人决定的一个很好的指标是评论&安培;每个应用程序的评级。我花了几周的时间才弄清楚如何将python正确地集成到这个App的Objective-c中,但这里是让你入门的最佳资源(请记住,ObjC只是C的超集):

I am the sole creator of Python for iOS so that is of course what I would recommend, but a good indicator for your personal decision is the reviews & ratings of each App. It took me weeks to figure out how to properly integrate python into Objective-c for this App but here is the best resource to get you started (keep in mind that ObjC is just a superset of C):

docs.python/c-api/

此外,这是一个调用 myModule 。等价的python将是:

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

import myModule pValue = myModule.doSomething() print pValue

在Objective-c中:

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); }

有关更多文档,请查看:扩展和嵌入Python解释器

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

更多推荐

Python for ios解释器

本文发布于:2023-06-13 00:04:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/670354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   ios

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!