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

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

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

问题

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

  1. <方法名>

示例:

  1. "/absfds/dclckd/dsf: {
  2. "reference": False,
  3. "type": "object",
  4. "value": {
  5. "functionName": "",
  6. "artifactPath": "",
  7. "branch": "develop",
  8. "buildType": "",
  9. "buildCommand": "",
  10. "repository": "",
  11. "storageClass": "STANDARD_IA",
  12. "handler": "包名加类名::方法名"
  13. },
  14. "volatile": True
  15. }

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

英文:

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

Syntax:

  1. &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中引用一个方法,只需使用其名称,但不加(),例如:

  1. &gt;&gt;&gt; import os
  2. &gt;&gt;&gt; os.getenv
  3. &lt;function getenv at 0x...&gt;
  4. &gt;&gt;&gt; os.getenv(&#39;EDITOR&#39;)
  5. &#39;nvim&#39;
  6. &gt;&gt;&gt; f = os.getenv
  7. &gt;&gt;&gt; f(&#39;EDITOR&#39;)
  8. &#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.

  1. &gt;&gt;&gt; import os
  2. &gt;&gt;&gt; os.getenv
  3. &lt;function getenv at 0x...&gt;
  4. &gt;&gt;&gt; os.getenv(&#39;EDITOR&#39;)
  5. &#39;nvim&#39;
  6. &gt;&gt;&gt; f = os.getenv
  7. &gt;&gt;&gt; f(&#39;EDITOR&#39;)
  8. &#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:

确定