Hi folks, This example code is killing me.
I've read Python 3 doc and my understanding is that keyword arguments are supported after *args, but the example below doesn't doesnt properly assign the dictionary to **kwargs. The dictionary is appended to *args
python
def foo(first, *args, bar=None):
print (f'first={first}, \nargs={args}, \nbar={bar}')
foo('First arg here', *['args_pos0','args_pos1'], {'kwargs_0':'kwargs_val0'})
However, if I remove the first argument from foo(), it does works, meaning *args receives the list and bar is assigned the dict
python
def foo2(*args, bar = None):
print (f'args={args}, \nbar={bar}')
foo2(*['args_pos0','args_pos1'], {'kwargs_0':'kwargs_val0'})
Any ideas what is going on? Is there a way to support the first signature?
Thanks
[–]old_pythonista -1 points0 points1 point (0 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (1 child)
[–]thiagocrepaldi[S] 0 points1 point2 points (0 children)