Python中等效于Java中双冒号(::)运算符的部分是:

huangapple go评论76阅读模式
英文:

Python equivalent of the double colon (::) operator in java

问题

在Java中,双冒号(::)操作符也被称为方法引用操作符。在Python中,与之等效的是:

<方法名>

示例:

"/absfds/dclckd/dsf: {
    "reference": False,
    "type": "object",
    "value": {
        "functionName": "",
        "artifactPath": "",
        "branch": "develop",
        "buildType": "",
        "buildCommand": "",
        "repository": "",
        "storageClass": "STANDARD_IA",
        "handler": "包名加类名::方法名"
    },
    "volatile": True
}

该处理程序位于一个 .json 文件中,该文件正在访问 Java 文件。在访问 Python 文件时,如何编写处理程序?处理程序是否保持不变?

英文:

What is the double colon(::) operator in java also known as method reference operator in Java equivalent in python ??

Syntax:

&lt;Class name&gt;::&lt;method name&gt;

Example:
&quot;/absfds/dclckd/dsf: {
&quot;reference&quot;: false,
&quot;type&quot;: &quot;object&quot;,
&quot;value&quot;: {
&quot;functionName&quot;: &quot;&quot;,
&quot;artifactPath&quot;: &quot;&quot;,
&quot;branch&quot;: &quot;develop&quot;,
&quot;buildType&quot;: &quot;&quot;,
&quot;buildCommand&quot;: &quot;&quot;,
&quot;repository&quot;: &quot;&quot;,
&quot;storageClass&quot;: &quot;STANDARD_IA&quot;,
&quot;handler&quot;: &quot;package along with class name::method&quot;
},
&quot;volatile&quot;: true

The handler is inside a .json file which is accessing java files. How to write the handler when it is accessing python files. Does it remain the same ?

答案1

得分: 2

这不是一个有效的JSON文件,至少不是这种格式。

要在Python中引用一个方法,只需使用其名称,但不加(),例如:

&gt;&gt;&gt; import os
&gt;&gt;&gt; os.getenv
&lt;function getenv at 0x...&gt;
&gt;&gt;&gt; os.getenv(&#39;EDITOR&#39;)
&#39;nvim&#39;
&gt;&gt;&gt; f = os.getenv
&gt;&gt;&gt; f(&#39;EDITOR&#39;)
&#39;nvim&#39;

(预计完成时间:如果os是一个类或类的实例,它的工作方式相同。)

英文:

This is not a valid JSON file, at least not in this format.

To get a reference to a method in Python, you just use its name but without (), eg.

&gt;&gt;&gt; import os
&gt;&gt;&gt; os.getenv
&lt;function getenv at 0x...&gt;
&gt;&gt;&gt; os.getenv(&#39;EDITOR&#39;)
&#39;nvim&#39;
&gt;&gt;&gt; f = os.getenv
&gt;&gt;&gt; f(&#39;EDITOR&#39;)
&#39;nvim&#39;

(ETA: it works the same way if os was a class, or an instance of a class.)

huangapple
  • 本文由 发表于 2020年3月16日 18:38:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/60704372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定