Bug or feature? Slash in os and os.path

M.-A. Lemburg mal at lemburg.com
Thu May 20 03:33:21 EDT 1999


Christian Tismer wrote:
> 
> Hi all,
> 
> What is the desired behavior of os.listdir, os.path.listdir
> and os.path.exists?
> 
> I wouldn't care if appending a slash is allowed or not,
> but it should always be consistent.
> 
> >>> os.path.exists('D:/Back/RsServer/gm/xmls/gm/cicos/') # oops
> 0
> >>> os.path.exists('D:/Back/RsServer/gm/xmls/gm/cicos') # ok
> 1
> >>> os.path.isdir('D:/Back/RsServer/gm/xmls/gm/cicos/') # oops
> 0
> >>> os.path.isdir('D:/Back/RsServer/gm/xmls/gm/cicos') # ok
> 1
> 

I'd say, all of these should return 1, like they do on Unix.
The fix is simple: just add a check for the trailing '/'
to the functions in ntpath.py and you should be set.

> >>> os.listdir('D:/Back/RsServer/gm/xmls/gm') # ok
> ['subsets', 'cicos', ...]
> 
> >>> os.listdir('D:/Back/RsServer/gm/xmls/gm/') # ok
> ['subsets', 'cicos', ...]
> >>>

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   225 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list