**kwargs parameter name has a "." in it creating an error
I am trying to pass an argument into a function with **kwargs allas some of the argument names contain a . and I get an error as code editor expect argument name and don't recognize it, likely because of the "."
def get_active_offers(**kwargs):
params = {}
for args in kwargs:
params[args]=kwargs.values()
response = api_request(params)
return response
test = get_active_offers(BasicFilters.PriceFrom="1")
is there a way around it (something like an f string for arguments?)
for the moment my solution has been to pass the name of the argument and the value as a list and naming it with a simpler name but I am trying to learn the proper way?
def get_active_offers(**kwargs):
params = {}
for args in kwargs.values():
params[args[0]]=args[1]
response = api_request(params)
return response
test = get_active_offers(argument = ["BasicFilters.PriceFrom","1"])
As one of the comments said, you can pass the argument as a dict:
def get_active_offers(**kwargs):
params = {}
for args in kwargs:
params[args]=kwargs.values()
response = api_request(params)
return response
test = get_active_offers(**{"BasicFilters.PriceFrom":"1"})
The above syntax of using **
with the argument is called "dictionary unpacking"