我有这样的代码:
class sampleClass(object):
def __init__(self):
super(sampleClass, self).__init__()
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么它在下面调用它自己的 super __init__?
我知道 super 用于调用父类的__init__(如果我错了请告诉我),但是这里它有什么作用?
在许多代码中,我看到其中包含函数的类,他们只是使用了pass短语并对其进行了一些评论.像python中的本机内置函数:
def copyright(*args, **kwargs): # real signature unknown
"""
interactive prompt objects for printing the license text, a list of
contributors and the copyright notice.
"""
pass
Run Code Online (Sandbox Code Playgroud)
我知道传球无所作为,它的那种冷漠和null短语,但为什么程序员使用这样的功能?
还有一些功能return ""如下:
def bin(number): # real signature unknown; restored from __doc__
"""
bin(number) -> string
Return the binary representation of an integer.
>>> bin(2796202)
'0b1010101010101010101010'
"""
return ""
Run Code Online (Sandbox Code Playgroud)
为什么程序员会使用这些东西?
我有 2 个网站,我想postMessage在它们之间使用 javascript。在我的主站点上,我在 emty html 文件中编写以下代码:
<html>
<script>
window.addEventListener("message",listener_,false);
function listener_(event) {
console.log('ok!');
<html>
<script>
window.addEventListener("message",listener_,false);
function listener_(event) {
console.log('ok!');
//console.log(event);
//console.log(event.data);
}
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
在其他站点中,我想调用 postmessage,我编写以下代码:
<script type="text/javascript">
window.onload = function() {
testfunction();
};
function testfunction(){
var childWin = window.open("http://my-main-site.com/indexjava2.html","child");
childWin = postMessage('message','*');
console.log(TipaltiIframeInfo.height);
}
</script>
Run Code Online (Sandbox Code Playgroud)
但经过多次尝试后还是不行。我的意思是 console.log('ok!'); 或console.log(事件); console.log(事件.数据);
不会在主站点的控制台上触发,
该怎么办?谢谢
我有一个字符串1.1.1.1.1,我想用_字符替换所有点.
我写了以下程序:
#!/bin/bash
var="1.1.1.1.1"
new2=${var/./_}
echo $new2
Run Code Online (Sandbox Code Playgroud)
但它只是用_字符串替换第一个点,结果是:
1_1.1.1.1
我怎么能用所有点替换_?
谢谢.
我在正则表达式中很弱,请原谅我提出这个问题,我有这样的字符串:
4H71NP35P2",""
80844UNWR2",""
53UT5Z7E09",""
963ZF761A4",""
9U30538OX8",""
F1CK67N510",""
308VWHR688",""
6I5E8XKL6H",""
Y42WHYY997",""
3SF73CDEGX",""
JGQB0X133N",""
5Y5Z956O45",""
XKMXJJA822",""
Y0ZO3N28O1",""
2F59677ZX7",""
77T513NIC9",""
RH799SKGN7",""
Run Code Online (Sandbox Code Playgroud)
我想在""之间添加一个字符串,我尝试了一些正则表达式代码,但没有一个工作.
因此我希望有类似的东西
4H71NP35P2","somthing1"
80844UNWR2","somthing2"
53UT5Z7E09","somthing3"
.
.
.
Run Code Online (Sandbox Code Playgroud)
谢谢.
python ×3
python-2.x ×2
python-3.x ×2
bash ×1
frontend ×1
html ×1
javascript ×1
null ×1
regex ×1
super ×1
web ×1