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.
Best Practices: Recognize when Pythonista is calling a script
-
Hi all,
I'm looking for a best practice way to recognize when Pythonista is calling a script (vs. being called from, say, Alfred, or just in a plain old terminal emulator).The best I can find is to
try
to import a Pythonista-only module, and work from there, but it seems pretty hacky. I looked around the documentation and didn't find anything.Any ideas?
-
If your script actually uses the Pythonista-only module when running there, but has an alternative code path for running on a Mac/PC (typical example: using
clipboard
), I don't think it's such a bad idea totry
importing the module and falling back to something else if you get anImportError
.On the other hand, if you're just interested in knowing where the script runs, without the code actually being different, you could for example use
platform.machine()
. -
@omz – Ah, great, I like that! So I can tell if pythonista the application is running it by try/catching an import for a Pythonista specific module, and I can also check the hardware with platform.machine(). Thanks for the solution.
-