What behavior would you expect?
Chris Angelico
rosuav at gmail.com
Fri Feb 20 01:21:51 EST 2015
On Fri, Feb 20, 2015 at 5:18 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> 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
Bikeshedding: That could be written as simply "if not fs". :)
ChrisA
More information about the Python-list
mailing list