问题标签 [positional-parameter]

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 投票
2 回答
9442 浏览

python - TypeError: __init__() 接受 2 个位置参数,但给出了 4 个

我的代码给出的错误为TypeError: __init__() takes 2 positional arguments but 4 were given. 试图寻找一个额外的论点,但找不到。

尝试了以前回答的问题,但没有得到任何适当的解决方案。

我的代码如下:

编译器给出如下运行时错误

0 投票
1 回答
31 浏览

bash - 标记字符串 - 错误的结果

错误的字符串标记化

从命令输出中提取应用程序版本

我希望这$2将具有价值19.08.19。但结果是19.08.19 14 25

0 投票
0 回答
34 浏览

ruby - ruby method arguments writen after method name and space leads to error

I write a method.

It works, but if I make a space after calling the method, it doesn’t work, why? Note that there is no difference wether there is a space between the method name and the parenthesis inside the definition of the method.

(repl):4: syntax error, unexpected ‘,’, expecting ‘)’ additionner (2,7)

in version: ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]

0 投票
1 回答
42 浏览

arrays - Bash - 如何将数组传递给函数,并在新函数中定义索引

我有这个当前函数用于创建菜单样式的数组(关联数组不能在场景中使用)。

这给了我菜单数组,{"host1" "ip1" "host2" "ip2" "host3" "ip3" 这非常适合我需要的东西,但现在我想重用这个函数来传递任何 2 个数组,就像这样。

编辑:我知道第二个示例传递了数组的整个元素列表。我想知道是否有办法传递和替换数组

0 投票
1 回答
511 浏览

java - How does Gradle's CopySpec filter method signature relate to the example given?

I am trying to implement something that will replace ${pattern} in xml files in my build.gradle file:

tokens: appears to take a Map. Again, how does this relate to the function signature?

Convert all properties with String values into a Map for input into tokens:

A look at the Gradle Javadoc reveals a filter function whose signature does not seem to match the examples. Particularly, the Map<String,?> and Class<? extends FilterReader> do not match the order in the examples as far as I understand them. Could somebody map the example to the function signature so that I understand what is going on?

Adds a content filter to be used during the copy. Multiple calls to filter, add additional filters to the filter chain. Each filter should implement java.io.FilterReader. Include org.apache.tools.ant.filters.* for access to all the standard Ant filters.

Filter properties may be specified using groovy map syntax.

Examples:

Specified by:

filter in interface ContentFilterable

Parameters: properties - map of filter properties filterType - Class of filter to add

Returns: this


Related:

How is a token replaced in a file for a Gradle build product?


Note:

What does not work is the SimpleTemplateEngine

0 投票
1 回答
56 浏览

bash - 在 Bash 脚本中,如何使用函数 `dirname` 将目录更改为文件的目录路径?

我想通过定义别名将目录更改为文件的目录:

但这不起作用。对于我如何重组它的任何想法表示赞赏。

0 投票
1 回答
495 浏览

python - 如何让 argparse 识别跟随可变长度可选参数的位置参数?

我正在编写一个脚本,用于合并多个输入文件,生成单个输出文件,并且我想使用argparse. 对我来说,最自然的方法是使用单个可选输入 , -i,它接受一个或多个输入文件名,后跟一个位置参数,表示输出文件名。这是我想到的一个例子:

当我打印由 创建的自动生成的帮助消息时argparse,调用签名看起来像我想要的那样:

但是,当我实际尝试运行脚本时,它会给出一个错误,提示我argparse错误地解析了最终的位置参数,就好像它被包含在选项列表中一样:

我的问题:是否有可能argparse正确处理这样的案例,将最终论点视为位置论点?或者是我接受“解决方法”解决方案的唯一选择,例如将输出文件名也转换为可选参数,例如,like-f --fname_out或类似。

如果不可能做我想做的事,那么我计划将其作为我的后备解决方案来实施。但是,在我接受一个不优雅的解决方法之前,我很好奇是否真的有可能以argparse“正确”的方式处理这个问题。

0 投票
0 回答
33 浏览

arrays - 使用带空格数组的命令行

如何传递某些值有空格的数组。我是说:

脚本.sh

我可以运行这个小脚本

我想在不更改脚本的情况下打印“ab,2”可以吗?

我发现实现它的唯一方法是:

有没有更聪明的方法?

0 投票
1 回答
102 浏览

python - 尝试在运行时在另一个内部创建具有仅位置参数的函数后引发 SystemError

有一些测试代码:

我收到以下错误:

但是,下面的代码按预期工作:

这个也是有效的:

我知道在未来的版本中,注释将不再在定义时进行评估;也可以在 3.7+ 版本中激活这种行为。就像是

也没有问题。但是,问题是关于函数定义时当前的奇怪行为。some_type绝不是 的局部变量func0,尽管 python 这么认为。一个更好的版本:

我已经阅读了PEP 570,但没有找到任何关于注释声明的内容。

我的python版本:

0 投票
2 回答
99 浏览

loops - 在 Raku 的内部循环中使用循环的位置参数

这是代码:

预期输出为:

但它给出了这个错误(可能是其他错误)

它看起来像主循环的位置变量,$^k不能$^v在内循环内部使用。如何解决?谢谢。更新:内循环内的错字已修复