英文:
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:
<Class name>::<method name>
Example:
"/absfds/dclckd/dsf: {
"reference": false,
"type": "object",
"value": {
"functionName": "",
"artifactPath": "",
"branch": "develop",
"buildType": "",
"buildCommand": "",
"repository": "",
"storageClass": "STANDARD_IA",
"handler": "package along with class name::method"
},
"volatile": 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中引用一个方法,只需使用其名称,但不加()
,例如:
>>> import os
>>> os.getenv
<function getenv at 0x...>
>>> os.getenv('EDITOR')
'nvim'
>>> f = os.getenv
>>> f('EDITOR')
'nvim'
(预计完成时间:如果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.
>>> import os
>>> os.getenv
<function getenv at 0x...>
>>> os.getenv('EDITOR')
'nvim'
>>> f = os.getenv
>>> f('EDITOR')
'nvim'
(ETA: it works the same way if os
was a class, or an instance of a class.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论