I have a python desktop application that needs to store user data. On Windows, this is usually in %USERPROFILE%\Application Data\AppName\
, on OSX it's usually ~/Library/Application Support/AppName/
, and on other *nixes it's usually ~/.appname/
.
There exists a function in the standard library, os.path.expanduser
that will get me a user's home directory, but I know that on Windows, at least, "Application Data" is localized into the user's language. That might be true for OSX as well.
What is the correct way to get this location?
UPDATE: Some further research indicates that the correct way to get this on OSX is by using the function NSSearchPathDirectory, but that's Cocoa, so it means calling the PyObjC bridge...
Can you create a desktop application using Python? Yes, you can. In this article, we will learn how to make a desktop application using the Tkinter library of Python. There are several libraries in Python, but Tkinter is one of the easiest ones among them.
Python is a cross-platform, interpreted, object-oriented programming language that is perfectly suited for Rapid Application Development, scripting, and connecting existing components together. Python uses a simple, easy to learn syntax, which focuses on readability to reduce the overall cost of program maintenance.
Kivy is a platform independent as it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it Does not mean that it can not be used on Desktops applications.
Well, I hate to have been the one to answer my own question, but no one else seems to know. I'm leaving the answer for posterity.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With