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

Bernhard Herzog bh at intevation.de
Tue Oct 7 08:53:33 EDT 2003


bokr at oz.net (Bengt Richter) writes:

> On Mon, 06 Oct 2003 15:23:42 +0200, Bernhard Herzog <bh at intevation.de> wrote:
>
>>
>>bokr at oz.net (Bengt Richter) writes:
>>
>>> 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 ;-)

That's also how I understood it.

[...]
> 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.

Certainly. I just don't think that the empty string should mean the
current directory, although one could argue that it would be consistent
with the interpretation of an empty string in sys.path.

> Maybe a ValueError exception consistently would be best,

+1

> I haven't bumped into the problem in a real use case,

I haven't either but ISTM that trying to use an empty string as a
directory name is likely the result of some error and thus should
produce an exception.

One scenario I can think if would be config files as read by
ConfigParser. Say you have a section which among other things contains
an option that is a directory name. If you want to explicitly set that
option to a Null value you could simply omit the value:

[images]
dir=


ConfigParser would give you an empty string:

>>> import ConfigParser
>>> c = ConfigParser.ConfigParser()
>>> c.read(["dummy.config"])
>>> c.get("images", "dir")
''
>>> 

Should that really mean "current directory" instead of "no directory
given"?

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/




More information about the Python-list mailing list