Forum Archive

Check if script is executed within Pythonista

elkrause

Hi!

I would like to write multi-platform scripts for Pythonista on iOS, Mac and Windows.

Do you know a way how a script which is executed within Pythonista can check that it is executed within Pythonista and not on a Mac?

stephen

@elkrause helo. you can try this

elkrause

Great @stephen thank you! It works well!

stephen

@elkrause outstanding! have a good one πŸ™ƒ

WyldKard

If you're only looking to determine which OS you're on (and not whether you're in the Pythonista IDE specifically), you can do that with:

from sys import platform

print(platform)

If you're on iPhone/iPad, platform should be "iOS". If you're on macOS, you should get "darwin". Windows should be "win32" I believe.

stephen

@WyldKard
~~almost correct ☺️ heres what i get get from print(platform.platform()) on iPad Air2~~

~~Darwin-19.3.0-iPad5,4-64bit~~

~~might be because of iPadOS?~~

Edit..

stand corrected...

print(sys.platform)

>>> ios

sorry πŸ˜‰πŸ˜Š

stephen

😞 just realised i can never trust the platform module again lol