0

I'm creating a very basic match-market solution that would be used in betting shops. I have a function that looks like this:

def create_market(name, match, providerID=str(uuid.uuid4()), market_kind=4, *market_parameters):

I want to call a function with only name, match and market_parameters while skipping the providerID, and market_kind (since these are optional)

Keep in mind that *market_parameters will be a tuple of dicts that will be sent inside the function. I unpack it like:

for idx, data in enumerate(args):
    for k, v in data.iteritems():
        if 'nWays' in k:
            set_value = v

When I set this dict like

market_parameters = {'nWays' : 5}

and call a function like create_market('Standard', 1, *market_parameters)

I can't seem to get the data inside the function body.

What am I doing wrong?

mutantkeyboard
  • 1,614
  • 1
  • 16
  • 44
  • 1
    *"`*market_parameters` will be a dict"* - tuple, for positional parameters; `**kwargs` would be the dictionary. – jonrsharpe Nov 24 '16 at 12:12
  • @jonrsharpe yes, that's correct :) I was about to write that *market_parameters will be an unknown number of dicts that would be passed as a list (tuple) into a function. – mutantkeyboard Nov 24 '16 at 12:18

1 Answers1

2

By unpacking it like *market_parameters, you send unpacked values as a providerID (if you have more values in your dictionary then as providerID, market_kind and so on).

You probably need

def create_market(name, match, *market_parameters,
                  providerID=str(uuid.uuid4()), market_kind=4):

and call function like:

create_market('Standard', 1, market_parameters) # you don't need to unpack it.

and if you want to set providerID or market_kind then:

create_market('Standard', 1, market_parameters, providerID=your_provider_id, market_kind=your_market_kind)
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48