Python argparse with optional positional and default None
Python argparse with optional positional and default None Question: Working with Python and argparse, trying to accomplish the following: $> my_app Namespace(positional=None) $> my_app file.txt somedir Namespace(positional=[‘file.txt’, ‘somedir’]) i.e., a positional argument of type list, whose default is None. I would expect the following code to accomplish this: p = argparse.ArgumentParser() p.add_argument("positional", nargs=’*’, default=None) print(p.parse_args()) …