On 09/07/18 08:26, Matěj Cepl wrote: > On 2018-07-07, 15:48 GMT, Guido van Rossum wrote: >> if validate(name := re.search(pattern, line).group(1)): >> return name > Except there is no error handling for situations when > re.search() returns None, so one shouldn't use it anyway (most > of the time). Which seems to me like another nice example why > one should stay away from this style as much as possible. I am > too lazy to be tempted into this > nice-example-terrible-production-code world. So wrap it in a try/except to capture the re.search returning None: try: if validate(name := re.search(pattern, line).group(1)): return name except TypeError: # No match case And this solution is even better if the validate function raises an exception rather than True/False which I think is much better than trying to do multiple steps : match = re.search(pattern, line) if match is not None: name = match.group(1) if name and validate(name): return name else: # No valid case else: # No Match case > Best, > > Matěj -- -- Anthony Flury email : *Anthony.flury at btinternet.com* Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4