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.
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.