Just wanted to know if this is a bad convention (which I am assuming is the case):
def foo(*args, **kwargs):
locals().update(kwargs)
try:
print(args, kwargs, a)
except NameError:
print('"a" is not defined')
Why do this?
Suppose you have a python dict
which serves as a config. This config may be lengthy and as a lazy programmer you do not want to have an enormous def
statement naming the kwargs
, you also do not necessarily always want to write kwargs["my_var"]
or inside the function def
write my_var = kwargs["my_var"]
.
Again I think this is not the best way to handle it. I am just curious if there might be another solution.