Questions tagged [argument-unpacking]

Use this tag for questions related with argument unpacking, a technique that allows Arrays and Traversable objects to be extracted/unpacked into argument lists/sequences.

is usually found in PHP, Python and Go.

144 questions
1
vote
1 answer

Lua flexible function argument unpacking in local function

I am working on command handler that needs to work in two environments. Below is a a small part of the function I am working on, which I think captures the problem. At least, I get the error message I need to adress. In the live environment, a…
1
vote
1 answer

pool.apply_async with multiple parameters

The below code should call two databases at the same time. I tried to do it with ThreadPool but run into some difficulties. pool.apply_async doesn't seem to allow multiple parameters, so I put them into a tuple and then try to unpack them. Is this…
Nickpick
  • 6,163
  • 16
  • 65
  • 116
1
vote
2 answers

Javascript: argument unpacking in function.prototype.bind()?

The closest I've seen is this, but it doesn't really help me since I need to bind some parameters for later use with setInterval. More specifically: [in] var d = function(l, m) { console.log(l); console.log(m); } [in]…
13steinj
  • 427
  • 2
  • 9
  • 16
1
vote
1 answer

std::pair assignment with downcast

For timeouts in event reactors and proactors I use a priority queue that also allows O(log(n)) random access removes of events (when the event is signalled/completes rather than a timeout occurring). I store…
Display Name
  • 2,323
  • 1
  • 26
  • 45
1
vote
4 answers

Unpacking multiple variables in a for loop over a dictionary

Can someone please tell me why I am getting an unpacking error in the below code? bucket = { 'a': 'Joe', 'b': 'Brooke', 'c': 'Scott', 'd': 'Sam', } for i, kv in enumerate(bucket): k, v = kv print i, k, v
tslaw04
  • 21
  • 1
  • 3
1
vote
2 answers

Python: Unpack individual strings from tuple using Unpacking asterisk argument

In the following code, I am trying to create a new word by iterating over all words fed as arguments of varying length, string type. I read here * operator makes it non keyword optional arguments. def gen_new_word(word1,*nwords): new_word='' t0=[i…
user2290820
  • 2,709
  • 5
  • 34
  • 62
1
vote
3 answers

What are the pitfalls of keyword argument unpacking of instance' __dict__?

I'm trying to make convenient passing some set of arguments to a number of functions (say 20). Consider the following MWE (of course I don't really consider doing additions in such way): def function(a, b): return a + b class summation: …
Michael Pankov
  • 3,581
  • 2
  • 23
  • 31
0
votes
0 answers

Can I use an inspect.Signature instance as a signature for function that an ide will see?

Can I use an inspect.Signature instance as a signature for function that an ide will see? I am asking because I want a way to requires specikic key value pairs, and a catch all type for unknown other keywords. Function signatures and kwargs let one…
0
votes
0 answers

Return a reference to unpacked dictionary in Python

There is a common way to pass arguments in Python like this: def foo(a1, a2): print(a1, a2) def my_dict(): return {'a1': 4, 'a2':5} foo(**my_dict()) ... 4 5 But now I want to move the asterisks inside my_dict function: def foo(a1,…
Ars ML
  • 49
  • 4
0
votes
0 answers

Two-column pandas dataframe unpacking into string variables of column names

I have a function that if you pass it some data identifier, it will return a pandas dataframe of that dataset. I've just added a new parameter that, when True, returns a second dataframe with metadata about the dataset. So the function can return…
Julia
  • 1
  • 1
0
votes
1 answer

ValueError: too many values to unpack (expected 5) in for loop in Pandas Dataframe

I have a huge dataframe that looks like df = pd.DataFrame([ [1, "1/1/2023", 1, 3], [1, "1/1/2023", 2, 2], [1, "1/1/2023", 3, 1], [1, "1/1/2023", 4, 4], [2, "11/9/2022", 1, 2], [2, "11/9/2022", 2, 3], [2, "11/9/2022", 3,…
0
votes
1 answer

print(*myVar) invalid syntax

Trying to print list items on individual lines as simply as possible following this: https://www.geeksforgeeks.org/print-lists-in-python-4-different-ways/ >>> myVar = [1, 2, 3, 4, 5] >>> print(*myVar) File "", line 1 print(*myVar) …
L0Lock
  • 147
  • 13
0
votes
1 answer

Python : * Operator in list comprehension

Evening all, I have recently discover the * operator to unpack my list. I find it quite elegant but I am a bit struggling with it. Please find below an example : from matplotlib.pyplot import Line2D COLOR_FCT = { "a": ["blue", "Al", "-"], "b":…
MatPl
  • 45
  • 4
0
votes
2 answers

How to unpack only values from nested dict in for loop

I have the following code mydict = { "key": { "k1": "v1", "k2": "v2", } } for k, (v1, v2) in mydict.items(): v1 and v2 actaully equals to k1 and k2, is there a way to extract v1 and v2 with any unpacking syntax? I tried to…
Paz
  • 72
  • 6
0
votes
2 answers

How to unpack a list of colons and NumPy Nones to index an array?

I am writing a program that will have an arbitrary number of : and None in arbitrary locations of an n-dimensional NumPy array. Therefore, I want a way to unpack these : and None axis operators into the [] that indexes an array and auto-populates…