os.listdir() bug in WinXp. Calling with empty string

Bengt Richter bokr at oz.net
Tue Oct 7 01:04:16 EDT 2003


On Mon, 06 Oct 2003 15:23:42 +0200, Bernhard Herzog <bh at intevation.de> wrote:

>
>bokr at oz.net (Bengt Richter) writes:
>
>> On Sun, 5 Oct 2003 07:29:34 -0400, "John Roth" <newsgroups at jhrothjr.com> wrote:
>>> The least surprising behavior
>>>here is to simply list the current directory. In other words,
>>>a null string would be equivalent to a string containing a single
>>>dot.
>>>
>> +1
>>
>> That intuitively matches well with arg-less invocation of ls or dir.
>
>-1
>
>Passing an empty string isn't an argless call.
True. I meant "argless" as in nothing more on the shell command line following ls or dir ;-)
>
>If you want os.listdir to be similar to ls, os.listdir() should be
>equivalent to os.listdir(".") (currently the string argument is
>required).
I agree, that would be cleaner, and easy to do with just path='.' as default arg.
 
>
>And for an empty string a brief test shows that ls with an empty string
>as argument behaves just like os.listdir("") (both on GNU/Linux system):
>
>$ ls ''
>ls: : No such file or directory
>
>>>> os.listdir("")
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>OSError: [Errno 2] No such file or directory: ''
>

But we also saw different behavior for u'' on various platforms,
so the question of normalizing empty-string behavior platform-independently
for Python comes up. Maybe a ValueError exception consistently would be best,
on the assumption that you should not normally generate that parameter value.

I haven't bumped into the problem in a real use case, so I have no big
preference other than consistent platform independent behavior.

Regards,
Bengt Richter




More information about the Python-list mailing list