This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author babou
Recipients babou
Date 2013-03-25.16:26:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364228813.43.0.916487849633.issue17545@psf.upfronthosting.co.za>
In-reply-to
Content
The empty path '' is considered as an acceptable path in os.path.join, and works as a neutral prefix:
print os.path.join('','aaa')  ===>  aaa
which seems rather natural.
But it raises an exception when used as a parameter to os.listdir.
Logically, it should then list the current directory.
(the alternative would be to raise an exception when os.path.join gets an empty argument).

The inconsistency became clear to me when I had to write the following function :

def listdirs(path,flist): # Appends to "flist" all paths to files that
            # start with "path". Argument "path" can be empty string ''.
    if path=='' : localist=os.listdir('.')
    else : localist=os.listdir(path)
    for f in localist :
        p=os.path.join(path,f)
        flist.append(p)
        if os.path.isdir(p) :
            listdirs(p,flist)
    return flist

The conditionnal is needed only to avoid the exception, while the code is unique afterwards.

This is related to Issue818059, but I did not see how that issue was resolved.

Furthermore, the case of the empty path as argument to os.listdir should be documented in http://docs.python.org/2/library/os.html
History
Date User Action Args
2013-03-25 16:26:53babousetrecipients: + babou
2013-03-25 16:26:53babousetmessageid: <1364228813.43.0.916487849633.issue17545@psf.upfronthosting.co.za>
2013-03-25 16:26:53baboulinkissue17545 messages
2013-03-25 16:26:53baboucreate