1

I'm working on a really simple python package for our internal use, and want to package it as a .egg file, and when it's installed/used I want it to access a text file that is placed in an appropriate place on the computer.

So where is the best place to put application data in python? (that is meant to be edited by users) How do I get my python package to automatically install a default file there?

note: I know about the Windows application data directory, but would like to avoid it, as it's nonportable and kind of cumbersome both for users to access and for my application to access.

1
  • well, probably windows, but tying it to a specific OS seems clunky. it's not somewhere in the site-packages dir?
    – Jason S
    May 17, 2010 at 20:43

2 Answers 2

3

os.path.expanduser('~')

4
  • 1
    that's useful but it's the user's home directory, not the appropriate application directory (which is ~/Application Data on WinXP, ~/Library for Mac OSX)
    – Jason S
    Mar 16, 2011 at 15:17
  • @Jason: Sure, but that's the easy part. Mar 16, 2011 at 15:25
  • You can't. But you can put them in a mapping and then use platform to decide which you should use. Mar 16, 2011 at 15:28
  • Don't forget that some platforms will localize the paths used too.
    – johnny
    Jul 20, 2012 at 22:38
0

Each OS will have it's own directory where application data is expected to exist. There does not appear to be a method that provides this path in a platform-independent manner. You can write your own function to do this for you by checking os.name and then returning the appropriate value depending on the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.