Tim
Tim

Reputation: 99428

What does Namespace mean?

>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-f', '--foo')
>>> parser.add_argument('bar')
>>> parser.parse_args(['BAR'])
Namespace(bar='BAR', foo=None)
>>> parser.parse_args(['BAR', '--foo', 'FOO'])
Namespace(bar='BAR', foo='FOO')
>>> parser.parse_args(['--foo', 'FOO'])
usage: PROG [-h] [-f FOO] bar
PROG: error: too few arguments

Is Namespace some keyword in Python?

Is it also used in other cases?

Thanks.

Upvotes: 0

Views: 80

Answers (1)

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26569

It's referring to the argparse.Namespace class. There's nothing special about it; it's not a keyword or anything.

Upvotes: 3

Related Questions