os.path.expanduser()

os.path.expanduser(path)[source]

Expand ~ and ~user constructions. If user or $HOME is unknown, do nothing.