问题标签 [argument-unpacking]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
153 浏览

javascript - What would be the best way to handle language files in NodeJS

I am currently working on a website and I want to implement a language file. Meaning, I want to be able to have a file called language.js, which contains an object of all code-generated strings.

An example:

I am unsure how I would be able to achieve this in a fast but functional way. I was planning to use util.format, but this takes every replacement as a single argument, rather than a table or array. In Lua, there is unpack() (Source), which unpacks a table into separate elements. I'm wondering if there is a similar function in JavaScript, or if there are better ways of handling the formatting of an unknown amount of variables to a string

0 投票
1 回答
248 浏览

arrays - Matlab 箱线图句柄/属性值

我正在尝试访问用于创建boxplot().

我创建了一个情节:

找到异常值的句柄:

获取异常值的数据:

问题是它返回这个:

因为有些地块有多个异常值。如何解压 1x2 双精度值?

0 投票
3 回答
36564 浏览

python - 按列解压缩 NumPy 数组

如果我有一个 NumPy 数组,例如 5x3,有没有办法一次将其逐列解包以传递给函数,而不是像这样:my_func(arr[:, 0], arr[:, 1], arr[:, 2])

有点像*args列表解包但按列。

0 投票
1 回答
4110 浏览

python - 按名称动态传递参数到函数

是否可以动态设置传递给函数的参数的名称?

像这样:

0 投票
4 回答
3027 浏览

python - 在字典的for循环中解包多个变量

有人可以告诉我为什么我在下面的代码中遇到解包错误吗?

0 投票
3 回答
4122 浏览

python - 带星号参数和不带星号参数的差异调用函数

我知道星号在 Python 中的函数定义中是什么意思。

不过,我经常看到带有以下参数的函数调用的星号:

第一个和第二个函数调用有什么区别?

0 投票
2 回答
1870 浏览

c++ - 在 C++ 中解压缩参数包

我有两个功能fg. f异步计算它的返回值并返回一个未来。现在,基于 的几个返回值f,我想调用g,但我想确保 的值的计算f并行发生。

考虑以下代码:

如何从函数的可变参数模板T中解压缩类型call_wrapper

0 投票
3 回答
753 浏览

python - 为 map() 的参数解包嵌套列表

我敢肯定有办法做到这一点,但我一直无法找到它。说我有:

那么我如何使用map(add, foo)它使其通过num1=1num2=2对于第一次迭代,即它通过add(1, 2),然后add(3, 4)对于第二次,等等?

  • 尝试map(add, foo)显然是add([1, 2], #nothing)第一次迭代
  • 尝试map(add, *foo)add(1, 3, 5)一次迭代

我想在第一次迭代map(add, foo)中做一些事情。add(1, 2)

预期输出:[3, 7, 11]

0 投票
1 回答
279 浏览

python - 如果变量不为空,则将参数解包到函数

如果变量不为空,我正在尝试将参数列表传递给函数。

这是变量:

但是这个变量有时可能是 None :

如果它不为空,我想从 shape_properties 中提取论点。这是我尝试过的:

我收到此错误:

错误代码向我暗示我不能在这种情况下使用 **args?

这是 add_textbox() 的样子:

0 投票
3 回答
14374 浏览

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

Does anybody know the reasoning as to why the unary (*) operator cannot be used in an expression involving iterators/lists/tuples?

Why is it only limited to function unpacking? or am I wrong in thinking that?

For example:

Why doesn't the * operator:

whereas when the * operator is used with a function call it does expand:

There is a similarity between the + and the * when using lists but not when extending a list with another type.

For example: