Best Practices: Recognize when Pythonista is calling a script
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
tryto import a Pythonista-only module, and work from there, but it seems pretty hacky. I looked around the documentation and didn't find anything.
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 to
tryimporting the module and falling back to something else if you get an
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
@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.