[issue16877] Odd behavior of ~ in os.path.abspath and os.path.realpath

Ian Shields report at bugs.python.org
Sun Jan 6 20:59:24 CET 2013


Ian Shields added the comment:

David, Tilde expansion is different to globbing. Globbing in Python doesn't automatically do tilde expansion either.
>>> glob.glob("~")
[]

Looking at the documentation, I don't think it would be practical to add documentation to each affected function - there are too many. Apart from abspath and realpath (which started this conversation), there are join, isdir, isfile, isabs, and many others in os.path. posixpath and the other path handling modules.

Maybe a note at the top of the module documentation (e.g. http://docs.python.org/3/library/os.path.html) which has two notes already. Something along the line of:

Unlike many shells, Python does not automatically do tilde expansion or variable substitution in paths. Use expanduser for tilde expansion or expandvars for variable substitution.

Or just simply
Use expanduser for tilde expansion or expandvars for variable substitution in paths as the other path functions do not do this automatically.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16877>
_______________________________________


More information about the Python-bugs-list mailing list