Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check if a script is running in Pythonista 2 or 3
import os
import sys
import plistlib
def get_bundle_identifier():
plist = plistlib.readPlist(os.path.abspath(os.path.join(sys.executable, '..', 'Info.plist')))
return '{CFBundleIdentifier}'.format(**plist)
def is_pythonista_3():
return get_bundle_identifier() == 'com.omz-software.Pythonista3'
def is_pythonista_2():
return get_bundle_identifier() == 'com.omz-software.Pythonista'
if __name__ == '__main__':
Copy link

cclauss commented Apr 3, 2020

PY3 = bytes != str

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment