Why this unpacking of arguments does not work?

The ** syntax requires a mapping (such as a dictionary); each key-value pair in the mapping becomes a keyword argument. Your generate() function, on the other hand, returns a tuple, not a dictionary. You can pass in a tuple as separate arguments with similar syntax, using just one asterisk: create_character = player.Create(*generate_player.generate()) Alternatively, fix your … Read more

Python: Splat/unpack operator * in python cannot be used in an expression?

Unpacking in list, dict, set, and tuple literals has been added in Python 3.5, as described in PEP 448: Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) on Windows (64 bits). >>> [1, 2, 3, *[4, 5, 6]] [1, 2, 3, 4, 5, 6] Here are some explanations for the rationale behind this change. Note that … Read more

What do ** (double star/asterisk) and * (star/asterisk) mean in a function call?

A single star * unpacks a sequence or collection into positional arguments. Suppose we have def add(a, b): return a + b values = (1, 2) Using the * unpacking operator, we can write s = add(*values), which will be equivalent to writing s = add(1, 2). The double star ** does the same thing … Read more

Python 3: starred expression to unpack a list

The *args calling convention is documented in the Expressions reference: If the syntax *expression appears in the function call, expression must evaluate to an iterable. Elements from this iterable are treated as if they were additional positional arguments; if there are positional arguments x1, …, xN, and expression evaluates to a sequence y1, …, yM, … Read more

Unpacking, extended unpacking and nested extended unpacking

My apologies for the length of this post, but I decided to opt for completeness. Once you know a few basic rules, it’s not hard to generalize them. I’ll do my best to explain with a few examples. Since you’re talking about evaluating these “by hand,” I’ll suggest some simple substitution rules. Basically, you might … Read more