def expand_path(path, follow_links=False):
path = os.path.expandvars(os.path.expanduser(path))<EOL>if follow_links:<EOL><INDENT>return os.path.realpath(path)<EOL><DEDENT>return os.path.abspath(path)<EOL>
Expand shell variables ("$VAR"), user directory symbols (~), and return absolute path

    >>> path0 = '~/whatever.txt'
    >>> path = expand_path(path0)
    >>> path.endswith(path0[2:])
    True
    >>> len(path) > len(path0)
    True
    >>> '~' in path
    False
    >>> path.startswith(os.path.sep)
    True