safe_path()

audeer.safe_path(path, *paths, follow_symlink=False)[source]

Expand and normalize to absolute path.

It uses os.path.realpath() and os.path.expanduser() to ensure an absolute path without .. or ~, and independent of the path separator of the operating system. If follow_symlink is False, the faster os.path.abspath() is used instead of os.path.realpath().

Warning

audeer.safe_path() is deprecated, please use audeer.path() instead.

Parameters
Return type

str

Returns

(joined and) expanded path

Examples

>>> home = safe_path("~")
>>> folder = safe_path("~/path/.././path")
>>> folder[len(home) + 1 :]
'path'
>>> file = safe_path("~/path/.././path", "./file.txt")
>>> file[len(home) + 1 :]
'path/file.txt'
>>> file = audeer.touch("file.txt")
>>> link = path("link.txt")
>>> os.symlink(file, link)
>>> os.path.basename(path(link))
'link.txt'
>>> os.path.basename(path(link, follow_symlink=True))
'file.txt'