On 1/1/20 10:02 AM, Steven D'Aprano wrote:
# Fail() is a function that raises an exception;
# __ is a special predefined Pattern that always matches.
result = match(vec, # object to match
Pattern(0, 'y', 'z'), handle_yz,
Pattern('x', 0, 'z'), handle_xz,
Pattern('x', 'y', 0), handle_xy,
Pattern('x', 'y', 'z'), handle_xyz,
__, Fail('not a vector')
)
But the cons...
* having to quote the names in the Pattern constructor is a pain.
And it means that you can't match a string directly?
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/SCU7K736PBUF3QGO7QJYIZXDMWZYKTL7/
Code of Conduct: http://python.org/psf/codeofconduct/