D
D
Dmitry Vyatkin2015-11-13 18:50:56
Python
Dmitry Vyatkin, 2015-11-13 18:50:56

How to pass positional elements to a function?

Good afternoon! Tell me how to pass *args to the function in such a way that, for example, the help parameter when passing is not defined as a string, but is interpreted as a parameter?
Example:

args = ['util', 'help=test']
parser.add_argument(*args)

Gives error " File "/usr/lib/python2.7/argparse.py", line 1280, in add_argument
kwargs = self._get_optional_kwargs(*args, **kwargs)
File "/usr/lib/python2.7/argparse. py", line 1410, in _get_optional_kwargs
raise ValueError(msg % tup)
"
parser.add_argument('util', help='test')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abs0lut, 2015-11-13
@dim137

args, kwargs = ['util'], {'help':'test'}
foo (*args, **kwargs)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question