Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created May 13, 2016 20:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaskollmer/44601c4bfef14fea7d0cf4a91a1542fd to your computer and use it in GitHub Desktop.
Save lukaskollmer/44601c4bfef14fea7d0cf4a91a1542fd to your computer and use it in GitHub Desktop.
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__':
print(is_pythonista_3())
print(is_pythonista_2())
@cclauss
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