views:

95

answers:

3

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.

A: 

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 manor. You can write your own function to do this for you by checking os.name and then returning the appropriate value.

unholysampler
A: 

In windows application data and config files use to be located in

C:\Documents and settings\userName\myfile

or

C:\Documents and settings\userName\Aplication Data\myfile

in linux (ubuntu) often application data of locally installed apps can be found in the user home directory

If as you indicate do not want to have these files in the OS default dirs, then you can put them in the same directory your executable is. In this way you can use relative paths (or no paths) in your script to save and read your data files. Absolutely portable

joaquin
+2  A: 

os.path.expanduser('~')

Ignacio Vazquez-Abrams
+1 right, neat. How great python is
joaquin