[issue26429] os.path.dirname returns empty string instead of "." when file is in current directory

Eryk Sun report at bugs.python.org
Wed Feb 24 13:21:34 EST 2016


Eryk Sun added the comment:

os.path.dirname is documented as the first element of os.path.split, which in turn is documented to be empty when there's no slash in the path. 

An empty string is treated as the current directory by os.path.abspath. This is in line with an empty element in the PATH environment variable. Also, Python's sys.path uses an empty string for the current directory. If you want a dot for display and logging purposes, normalize via os.path.normpath:

    >>> os.path.normpath('')
    '.'

----------
nosy: +eryksun

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


More information about the Python-bugs-list mailing list