Good people -
In scripts it is useful to refer I/O operations to the home directory. Buried somewhere in the net I have found the following elegant way to do this independent of the OS:
homeDir = os.path.expanduser('~')
It works under Windows and Linux, and on Macs.
HP
OS independent retrieval of home directory
Re: OS independent retrieval of home directory
There's a function called "_expandpath" in interactive.py that basically pipes a path string through expand[user|vars|whatnot] and so basically you can pass in something like:
and get something like '/tmp/jbeavers/filename.ext' returned.
Code: Select all
_expandpath('/tmp/test/../$USER/./filename.ext')
and get something like '/tmp/jbeavers/filename.ext' returned.