OS independent files

Simon Forman rogue_pedro at yahoo.com
Thu Aug 3 15:44:04 EDT 2006


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.

Google groups has a very good search.

> 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)?

Try os.path.expanduser('~') (in
http://docs.python.org/lib/module-os.path.html) or you could just look
up the HOME environment variable in os.environ, but I don't know if
windows sets this correctly in all cases.

(os.environ is documented in
http://docs.python.org/lib/os-procinfo.html)

Peace,
~Simon




More information about the Python-list mailing list