[Python-ideas] Null coalescing operators
Terry Reedy
tjreedy at udel.edu
Mon Sep 21 22:23:03 CEST 2015
On 9/21/2015 10:56 AM, Paul Moore wrote:
> By the way, in your example you're passing on the "none or useful"
> property by making substr be either the matched value or None.
I agree that dealing with None immediately is better.
In real
> life, I'd probably do something more like
>
> mo = re.match(needle, haystack)
> if mo:
> process(mo.group())
> else:
> no_needle()
try:
process(re.match(needle, haystack).group())
except AttributeError: # no match
no_needle()
is equivalent unless process can also raise AttributeError.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list