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?

2
  • 1
    "*market_parameters will be a dict" - tuple, for positional parameters; **kwargs would be the dictionary. Commented Nov 24, 2016 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. Commented Nov 24, 2016 at 12:18

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Yes. That's it. Thank you @Yevhen Kuzmovych. You're a life saver.
@mutantkeyboard I am not sure what you are trying to do but kwargs can be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.