Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pythonista and ctypes
-
I've been an (almost) everyday user of Pythonista, as it's really cool to have a Python IDE right at my fingertips, no need for a computer, yay! And I have to say it's absolutely amazing! (BTW, I'm waiting impatiently for updates, are there any planned?) I mean, a full Python interpreter on iOS is a marvel already, but this is a fully featured IDE, just blew my mind when I first installed it a few years ago.
Now, I've got a question about the
ctypes
module. How is it useful in Pythonista? As far as I understand, one of its primary goals is to allow people to run C functions from Python, but it's absolutely impossible on iOS (or is it?) because there's no way to sign that C code... I even can't load libc, simply because it's not here, andctypes.util.find_library
doesn't find anything. However, I have to say that it works perfectly on jailbroken devices where libc is installed, but for non-jailbroken ones,ctypes
is almost useless.Or am I missing the point? Is it possible to call standard C functions through
ctypes
in Pythonista? What do I usectypes
for, if not for calling C functions? According to the docs, I can use C types and work with memory, but it's not that useful... or is it? -
One difference is that in pythonista all libraries are static libraries. Most people use ctypes along with
objc_util
to access ios frameworks. When you import objc_util, you get ac
variable that represents the CDLLfrom objc_util import * >>> c <CDLL 'None', handle fffffffe at 0x85c604c> >>> print(c.time(None))
there are lots of cool things that can be done with either objc frameworks, or the statically compiled ios libraries
-
(Note: I wrote this before @JonB but then my connection acted up, sorry if I'm duplicating anything said above.)
ctypes
is definitely useful in Pythonista without a jailbreak, it's justctypes.util.find_library
that doesn't work. All the libraries that you'd expect do exist in/usr/lib
and/System/Library/Frameworks
, however because of iOS restrictions they are invisible in the filesystem, which causesctypes.util.find_library
to think that they don't exist. You can still load them, but you need to specify the full path (likectypes.CDLL("/usr/lib/libSystem.dylib")
).You should also be aware that most iOS frameworks (Foundation, UIKit, etc.) are based on Objective-C and not just pure C. It is possible to use Objective-C classes with
ctypes
, however this requires a lot of manual work, so Pythonista comes with anobjc_util
library that makes Objective-C classes and objects very accessible. For some examples, see Pythonista's built-in docs onobjc_util
and the example scripts that come with the app.The community has done some pretty amazing things with the APIs usable via
objc_util
, see https://github.com/Pythonista-Tools/Pythonista-Tools/blob/master/ObjC Tools.md. (You'll also find that half of all forum threads containobjc_util
code of some kind.)As for updates to Pythonista, @omz is definitely working on new things. The current beta version has a bunch of new features, most importantly Python 3.6 instead of 3.5. It also extends Pythonista's URL scheme to allow running code snippets by opening a URL (don't worry, you see the code and have to confirm before anything is run) and includes more third-party libraries (such as
openpyxl
) and a bunch of small improvements and bugfixes. I have no idea when a new update will be released publicly, I don't think @omz makes any release date promises. -
@dgelessus, woah, I bet Python 3.6 support is gonna be super cool! Is there any way to get the beta? Maybe through TestFlight? If so, do you know how to sign in for testing? The Apple Help discusses this from the developer's point of view and says that a tester must somehow provide their e-mail address to the developer, but how to actually do this isn't clear.
Yeah, I didn't think about trying to hard-code the path. This is actually what I use on a jailbroken device :P
-
@JonB, didn't know about the
c
variable, this is exactly what I was looking for, thank you! -
Right, TestFlight only provides distribution of the beta app, it doesn't provide a standard way to sign up to beta test an app, it's up to the developer how to handle that. In the case of Pythonista, omz has set up this Google Form where you can enter your Apple ID to get access to the Pythonista beta. I think this is a manual process though, so there's no guarantee how quickly you'll receive the actual TestFlight invitation.
-
@dgelessus, where did you get the link to this Google Form? Has it been posted on the Pythonista's site or in Twitter or via Slack? Is there any official source? Please provide the link from where you copied this.
-
It was originally posted on the forums in the "Python 3.x Progress Update" thread here. Though every time someone asks I just go into Slack and search for "from:me beta form" to find the last time where someone asked and I reposted the link. ;)
-
To be quite honest, I haven't added new beta testers from the list in a while. It's a bit tedious to do, and I feel like I currently have enough beta testers, but I might start adding new ones when 3.2 gets closer to release.
-
@omz, anyway, I've filled in the form, so now you have one more Pythonista fan ready for beta testing! Keep up the good work!