'Namespace' object is not iterable
5.9.10.113/66995207/namespace-object-is-not-iterable08.04.2021 · 1 answer. answered 2021-04-08 21:59 Green Cloak Guy. parser.parse_args() returns a Namespace object, which is an object whose attributes represent the flags that were parsed.It is not iterable. It seems like you want to get the command-line arguments given after -f, in which case you would take that particular flag out of the Namespace object: ...
Issue 11076: Iterable argparse Namespace - Python tracker
bugs.python.org › issue11076For the doc section, I’d prefer to de-emplasize the specific use case of **kwargs, in favor of mentioning dict conversion in a general way: Converting the namespace to a dict ^^^^^ Namespace objects are iterable so you can easily convert them to a :class:`dict`:: args = parser.parse_args() argdict = dict(args) This makes it easy to introspect the namespace or to pass the command-line arguments to a function taking a bunch of keyword arguments:: somefunction(**dict(parser.parse_args ...
python - 'Namespace' object is not iterable - Stack Overflow
stackoverflow.com › questions › 66995207Apr 08, 2021 · parser.parse_args () returns a Namespace object, which is an object whose attributes represent the flags that were parsed. It is not iterable. It seems like you want to get the command-line arguments given after -f, in which case you would take that particular flag out of the Namespace object: print (sorthelper.sortNumbers (args.f)) Also, your code as you currently have it will print None, because sortNumbers () doesn't return anything.