Steven D'Aprano wrote:
> and your code will break. Better and safer is:
>
>
> def main(): # parse the args and call whatever function was selected
> args = parser.parse_args(sys.argv[1:])
> try:
> func = args.func
> except AttributeError as err:
> parser.print_help()
> else:
> func(vars(args))
I don't think this is any better. You are reponding on a programming error
in the script as if the user had provided erroneous input. Very confusing.
Just
args.func(vars(args))
will produce a traceback if the programmer made an error and a help message
if the user provides arguments that are not recognized.
That's how it should be.
--
https://mail.python.org/mailman/listinfo/python-list