question of style

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jul 5 18:20:32 CEST 2009


On Sun, 05 Jul 2009 06:12:25 -0700, Paul Rubin wrote:

>> There are three natural approaches to (say) re.search() for dealing
>> with failure:
>> 
>> (1) return a sentinel value like None; (2) return a matchobject which
>> tests False; (3) raise an exception.
> 
> 4. Have re.search return a bool and possible matchobject separately:
> 
>    put_match_here = []
>    if re.search(pat, s, target=put_match_here):
>       do_something_with(put_match_here[0])

Wow. I never for the life of me thought I'd see an experienced Python 
programmer re-implement Pascal's VAR parameters.

That is... hideous. Returning a (flag, matchobject) tuple is the height 
of beauty in comparison.



-- 
Steven



More information about the Python-list mailing list