OS independent files

Gerhard Fiedler gelists at gmail.com
Thu Aug 3 16:08:23 EDT 2006


On 2006-08-03 16:21:13, crystalattice wrote:

> I'm sure this has been addressed before but it's difficult to search
> through several thousand postings for exactly what I need, so I
> apologize if this a redundant question.
> 
> I've figured out how to use os.path.join to make a file or directory
> location prior to pickling something to it.  But I have a question
> about it.  In Windows I can make a file with this:
> 
> os.path.join("C:", "myfiles", "myfile.dat")
> 
> If I want to make sure the file/directory is made in a user's home
> directory (e.g. /home/users/path/to/file) but also compatible w/
> Windows, how would I rewrite this (if required)?

On more recent systems at least (2k, XP) you have the following environment
variables. The values below are typical values; they are not necessarily
like that.

USERNAME=<user>
HOMEDRIVE=C: 
HOMEPATH=\Documents and Settings\<user>
USERPROFILE=C:\Documents and Settings\<user>
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\<user>\Application Data

APPDATA\<applicationname> is a typical place to put application data.

Gerhard




More information about the Python-list mailing list