My script should start a demo mode, when the no parameters are given. I tried this:
args = parser.parse_args()
if len(args) == 0:
run_demo()
else:
# evaluate args
Which gives a *** TypeError: object of type 'Namespace' has no len()
as args
is no list.
How would I achieve what I want?
Don't use argparse. Instead just use
sys.argv
.argparse
creates a Namespace, so it will always give you a "dict" with their values, depending on what arguments you used when you called the script.Here's what I've done in the past: