In python 2.7.12 I get an error if I do not pass arguments, while in python 3.5.2 I do not get the error (it fails silently). Stumbled on this during my migration of my python 2.7 code to python 3.5 for django. Here is the console output: D:\util\python\test>py -3 test_argparse.py 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22🔞55) [MSC v.1900 64 bit (AMD64)] Use subparsers: True Namespace(command=None) D:\util\python\test>py -2 test_argparse.py 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] Use subparsers: True usage: test_argparse.py [-h] command ... test_argparse.py: error: too few arguments D:\util\python\test>
I am not an expert with argparse since I just started using it (and it has quite a lot of features which are not all self-explaining to me). But if I didn't misunderstand something it should behave like the python 2.7 version: If I do not pass any command I am told that I missed the parameter. Or: - are there some parameters I missed to make them behave equally? - what is the intention to fail silently?
Based on the usage output, it looks like the subcommand is required, but I'm not sure if there are cases where a subcommand could be optional. David, can you advise? usage: test_argparse.py [-h] command ...