What behavior would you expect?
Paul Rubin
no.email at nospam.invalid
Fri Feb 20 01:18:10 EST 2015
Dan Sommers <dan at tombstonezero.net> writes:
> 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.
Empty string would be bad. Sometimes I like to simulate an option type,
by returning the value as a 1-element list if there's a value, otherwise
as an empty list. So you could say
filename = get_filename(...)[0]
if you want an exception in the failure case, or you could do something
like
fs = get_filename(...)
if len(fs) == 0: ... # didn't get a filename
More information about the Python-list
mailing list