Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 0.41 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import os
  2.  
  3. def path(*segs):
  4.     """
  5.     CWD and `~` aware path construction. Start a segment with `/` for absolute paths.
  6.     *(Example, on my machine)*
  7.     >>> path('sub', 'dir')
  8.     /Users/jacob/src/tmp/sub/dir
  9.     >>> path('~', 'src', 'project', 'pkg')
  10.     /Users/jacob/src/project/pkg
  11.     """
  12.     cand = os.path.expanduser(os.path.join(*segs))
  13.     if cand[0] != '/':
  14.         cand = os.path.abspath(cand)
  15.     return cand