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
2
votes
3 answers

argument unpacking and assignment to class variables

Hi I have the following code, which attempts to create an instance of a class and assign argument values to it. I am trying to use *args to do this as follows: def main(): testdata = ['FDR', False, 4, 1933] apresident = President(testdata) …
domoarigato
  • 2,802
  • 4
  • 24
  • 41
1
vote
2 answers

Unpack multiple dictionaries as functional arguments without repeating double asterisk

I use API with long name of argument parameters. Consequently, I create following dictionaries for most common combinations of values which are then unpacked in function calls. a_T = {'API parameter a': True} a_F = {'API parameter a': False} b_100…
aeiou
  • 337
  • 1
  • 7
1
vote
1 answer

How can I use the value of a variable as a keyword in a function definition?

I'm passing an object to a function definition and would like to use the object as the 'key' within another function call but I'm unsure on how to do this. Below is an example of what I'm trying to achieve as I'm not sure on how this can be…
user17507778
1
vote
2 answers

Unpacking arguments: how to stop a list from turning to a nested list

I have created a function called other_func that results in a list, for example: [12,322,32] I want to create a function that will receive the other function and it will sort this list. I want to use *args as seen below, to better understand how it…
saZ
  • 89
  • 7
1
vote
1 answer

Is Python dictionary unpacking customizable?

Is there a dunder method which corresponds to using the dictionary unpacking opertator ** on an object? For example: class Foo(): def __some_dunder__(self): return {'a': 1, 'b': 2} foo = Foo() assert {'a': 1, 'b': 2} == {**foo}
Austin
  • 299
  • 1
  • 17
1
vote
1 answer

Maximum of multiple numpy arrays

We can compute the element-wise maximum of 3 numpy arrays: import numpy as np A = np.arange(20).reshape((4, 5)) # any 4x5 array B = np.maximum(A, A+7, A+2) # working But why doesn't np.maximum accept multiple arrays from an "unpacking"? L…
Basj
  • 41,386
  • 99
  • 383
  • 673
1
vote
2 answers

Is unpacking variadic using array(or initializer_list) trick optimize-safe?

Since C++14 cannot use fold expression, in order to make a function that calls bar on each variadics, one have to use function overloading. template void foo(Arg arg) { bar(arg); } template void…
김선달
  • 1,485
  • 9
  • 23
1
vote
2 answers

Unpacking array values to Class variables in Cpp

I want to unpack array values to different class variables but for that I am getting an error. auto [SendLowROS.motorCmd[FR_0].Kp, SendLowROS.motorCmd[FR_1].Kp, SendLowROS.motorCmd[FR_2].Kp, SendLowROS.motorCmd[FL_0].Kp,…
Tahir Mahmood
  • 305
  • 1
  • 11
1
vote
0 answers

How to find length of parameter input of function?

I'm trying to use Scipy's ODR to fit various different curves to data. These curves have to be given as an ODR Model, which is defined by a function. This function has two arguments: p and x. p is a list of the parameters that will be optimised.…
1
vote
2 answers

Python: can I unpack arguments without calling a function?

I have dict that I want to convert to several different objects. For instance: Currently Have kwargs = {'this': 7, 'that': 'butterfly'} And I want to convert it, maybe using something similar to function argument unpacking, but without actually…
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
1
vote
2 answers

Why does this print `3 {}` and not `2 {'a': 3}`?

def f(a=2, **b): print(a,b) f(**{'a':3}) Why does this print 3 {} and not 2 {'a': 3}? I can understand why it printed 3 {} if it was f(a=3) but I don't understand the output in this case.
user14095422
  • 79
  • 1
  • 7
1
vote
1 answer

How to unpack a tuple right from out parameter?

Let's say I have a dictionary with points. So I could then write: if (dict.TryGetValue(key,out (double x,double y) point)) point.x ... But how do get rid of point and unpack the elements of the tuple right away? I have something like this in…
greenoldman
  • 16,895
  • 26
  • 119
  • 185
1
vote
2 answers

How to wrap list functions in python?

I cannot accurately reflect this problem into title. I want to use list, func(*args) and Pool.map without errors. Please see below. ▼Code def df_parallelize_run(func, arguments): p = Pool(psutil.cpu_count()) df = p.map(func, arguments) …
Tomoand
  • 91
  • 1
  • 1
  • 7
1
vote
1 answer

Is it possible to unpack a dictionary of parameters in a JuliaDB push!() function?

I recognize that JuliaDB may still be a bit rough around the edges, but I was wondering if it's possible to do something like this: push!(rows(mse_table), table_params...) # add row Instead of something like this: push!(rows(mse_table),…
bug_spray
  • 1,445
  • 1
  • 9
  • 23
1
vote
1 answer

Is there a Fortran equivalent of unpacking a list of arguments in Python?

I'm writing my first numerical optimization program (Newton's method) and my first Fortran program too. I started with Python to understand the first problem and now I'm porting to Fortran to work on the other. (One thing at a time, right?) In…
user7851115