def collapse_user(fp):
    """
    Converts a path back to ~/ from expanduser()
    """
    home_dir = os.path.expanduser("~")
    abs_path = os.path.abspath(fp)
    return abs_path.replace(home_dir, "~")
def collapse_user ( fp ) : home_dir = os . path . expanduser ( "~" ) abs_path = os . path . abspath ( fp ) return abs_path . replace ( home_dir , "~" )
Converts a path back to ~/ from expanduser()