Sam Hooke

Python argparse

There is no need to write arguments --like_this.

You can do arguments --like-this, and argparse will convert the - characters to _.

For example:

Passing arguments --like this
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("--like-this", type=int)
>>> args = parser.parse_args("--like-this=123".split())
>>> args
Namespace(like_this=123)
>>> args.like_this
123