Created
April 11, 2012 08:57
-
-
Save jacob414/2358083 to your computer and use it in GitHub Desktop.
Swiss army path function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def path(*segs): | |
""" | |
CWD and `~` aware path construction. Start a segment with `/` for absolute paths. | |
*(Example, on my machine)* | |
>>> path('sub', 'dir') | |
/Users/jacob/src/tmp/sub/dir | |
>>> path('~', 'src', 'project', 'pkg') | |
/Users/jacob/src/project/pkg | |
""" | |
cand = os.path.expanduser(os.path.join(*segs)) | |
if cand[0] != '/': | |
cand = os.path.abspath(cand) | |
return cand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment