How to make, that when transferring to a function named arguments, the names of these arguments are in a variable? Like that:
x = 'name' def a(name = None) : pass a(x = 'John') How to make, that when transferring to a function named arguments, the names of these arguments are in a variable? Like that:
x = 'name' def a(name = None) : pass a(x = 'John') You can use the kwargs pattern:
def test(**kwargs): if kwargs: for k,v in kwargs.items(): print('{}:\t{}'.format(k,v)) In [279]: test(first_name='John', last_name='Doe') last_name: Doe first_name: John or so:
In [282]: parms = {'par1': 'val1', 'par2': 'val2'} In [283]: test(**parms) par2: val2 par1: val1 Source: https://ru.stackoverflow.com/questions/539141/
All Articles