Created
April 29, 2020 13:04
-
-
Save kotano/dd49a22fe788b0b33a5cfbd767d09636 to your computer and use it in GitHub Desktop.
Multiplatform path to appdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APPNAME = "MyApp" | |
import sys | |
from os import path, environ | |
if sys.platform == 'darwin': | |
from AppKit import NSSearchPathForDirectoriesInDomains | |
# http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains | |
# NSApplicationSupportDirectory = 14 | |
# NSUserDomainMask = 1 | |
# True for expanding the tilde into a fully qualified path | |
appdata = path.join(NSSearchPathForDirectoriesInDomains(14, 1, True)[0], APPNAME) | |
elif sys.platform == 'win32': | |
appdata = path.join(environ['APPDATA'], APPNAME) | |
else: | |
appdata = path.expanduser(path.join("~", "." + APPNAME)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment