Post #2445756
2026-04-30 00:46 UTC
If you want to more deeply customize the message shown to the user, you can raise an argparse.ArgumentTypeError instead of a ValueError:
def date(string):
try:
return dt.date.fromisoformat(string)
except ValueError:
message = "invalid YYYY-MM-DD date: {string!r}"
raise argparse.ArgumentTypeError(message) from None
If we had raised a ValueError, the printed message will be prefixed with "argument date: ". Not so bad, but sometimes unwanted.
🧵 (3/3)
Replies (1)
-
@SaguaroLynx@c.im 2026-04-30 15:16
@treyhunner@mastodon.social Nice! This helps me improve my Python programming skills and my UX design skills! 8- )