What behavior would you expect?

Dan Sommers dan at tombstonezero.net
Fri Feb 20 00:40:52 EST 2015


On Fri, 20 Feb 2015 16:16:50 +1100, Chris Angelico wrote:

> On Fri, Feb 20, 2015 at 3:54 PM, Dan Sommers <dan at tombstonezero.net> wrote:
>> if there are no
>> values to return, then return an empty collection.
> 
> That one makes sense only if you were going to return a collection
> anyway, though. If you were going to return a string, returning an
> empty list on failure makes no sense. Hence the notion of returning a
> "non-string".

I think I came in a little late, and saw "2. no files match the given
pattern," in which case I'm sticking to my story and returning an empty
list.

The original problem was "to search a directory and return the name of
the most recent file matching a given pattern."  I'd still prefer an
exception to None, and we agree on that an empty string is bad because
it's not a non-string and it could be too easily mistaken for a
filename.



More information about the Python-list mailing list