os.listdir() bug in WinXp. Calling with empty string
tjreedy at udel.edu
Sat Oct 4 23:30:37 CEST 2003
"Hannu Kankaanp??" <hanzspam at yahoo.com.au> wrote in message
news:840592e1.0310040736.83c9bc3 at posting.google.com...
> This may be a bug or simply a strange result of undefined
> behaviour, but this is what I get with Python 2.3.2 on
> Windows XP:
> >>> import os
> >>> os.listdir('')
> [ filenames in the current directory, e.g. c:\python\ ]
> >>> os.listdir(u'')
> [ filenames in the drive's root directory, e.g. c:\ ]
On Win98, *both* calls list root directory. listdir(path) must pass
path to os system call and print response or raise exception as
determined by os response.
>Maybe os.listdir() behaviour is undefined for empty strings,
It seems to be defined as whatever the os does with empty strings,
which is not much more useful. You could open SF bug report listing
various XP, W98, Linux behaviors and suggest that listdir def be
changed to 'if path: current behaviour; else: raise exception'.
Terry J. Reedy
More information about the Python-list