Saturday, December 20, 2008

make python understand ~ for home directories

Python does not automatically expand ~ for user home directories. There is a function in os.path that does that for you:

mypath = os.path.expanduser('~/somepath')
mypath == '/home/nick/somepath'

No comments: