您可能想考慮使用Unipath。對路徑計算的許多輔助功能以及字符串的路徑計算(子類海峽或Unicode)
原來這是一個在Unix上:https://github.com/mikeorr/Unipath
在Windows上一個工作太(我做了一些修正,以它):https://github.com/sesas/Unipath
>>> import unipath
>>> p = unipath.Path()
>>> p
Path(u'.')
>>> p.absolute()
Path(u'C:\\Python27\\Lib\\idlelib')
>>> p.child('hello_world')
Path(u'.\\hello_world')
>>> p = unipath.Path(__file__) # cannot actually do this in IDLE
>>> dir(p)
['__add__', '__class__', '__contains__', '__delattr__', '__dict__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__',
'__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__',
'__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'__weakref__', '_formatter_field_name_split', '_formatter_parser', '_new_helper', '_walk',
'absolute', 'ancestor', 'atime', 'auto_norm', 'capitalize', 'center', 'chdir', 'child',
'chmod', 'components', 'copy', 'copy_stat', 'copy_tree', 'count', 'ctime', 'cwd', 'decode',
'encode', 'endswith', 'exists', 'expand', 'expand_user', 'expand_vars', 'expandtabs',
'ext', 'find', 'format', 'index', 'isabsolute', 'isalnum', 'isalpha', 'isdecimal',
'isdigit', 'isdir', 'isfile', 'islink', 'islower', 'ismount', 'isnumeric', 'isspace',
'istitle', 'isupper', 'join', 'lexists', 'listdir', 'ljust', 'lower', 'lstat', 'lstrip',
'mkdir', 'move', 'mtime', 'name', 'needs_update', 'norm', 'norm_case', 'parent',
'partition', 'pathlib', 'read_file', 'rel_path_to', 'relative', 'remove', 'rename',
'replace', 'resolve', 'rfind', 'rindex', 'rjust', 'rmdir', 'rmtree', 'rpartition',
'rsplit', 'rstrip', 'set_times', 'size', 'split', 'split_root', 'splitlines', 'startswith',
'stat', 'stem', 'strip', 'swapcase', 'title', 'translate', 'upper', 'walk', 'write_file',
'zfill']
但這只是問題的一小部分。原來我想'os.path.realpath',只是它不能解析'〜/' – tkbx