python PEP 8 linter 不喜欢这样:
assert type(a) == type(b)
Run Code Online (Sandbox Code Playgroud)
它告诉我改用“isinstance()”。但是要使用isinstance
我必须做类似的事情
assert isinstance(a, type(b)) and isinstance(b, type(a))
Run Code Online (Sandbox Code Playgroud)
这似乎更笨拙,我真的不明白这一点。
linter 是否以某种我看不到的方式明智?或者我在某些方面是明智的,linter 看不到?
这是一个 HTML 页面,在左上角显示三个方形 div:
window.addEventListener('load', function () {
console.log('load event has fired')
window.scrollTo(500, 0);
// setTimeout(function() { window.scrollTo(500, 0); }, 0);
})
Run Code Online (Sandbox Code Playgroud)
body { height: 100vh }
.bigwidth {
width: 2000px;
display: block;
}
.square {
width: 100px;
height: 100px;
display: block;
position: absolute;
}
.greenish {
background-color: #75af99;
}
.redish {
background-color: #ff9b98;
}
.bluish {
background-color: #aabbff;
}
.whiteish {
background-color: #eaeaea;
}
* {
padding: 0;
margin: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class="whiteish bigwidth" style="height:100%;">
<div class="square greenish" style="left:50px; …
Run Code Online (Sandbox Code Playgroud)好的,我完全期望因为问一些愚蠢的(或至少是重复的)事情而火上浇油,但是在附加的代码段中,为什么我必须使用window.getComputedStyle
来访问 CSS 应用的样式?我的印象是该.style
字段至少会反映最初由 CSS 应用的样式,和/或从那时起手动更改的样式。
如果不是,那么控制元素.style
字段中反映(以及何时)反映哪些属性的确切规则是什么?
setTimeout(() => {
console.log("the bckg color:", reddish.style.backgroundColor);
console.log("the width:", reddish.style.width);
console.log("from a computed style:", window.getComputedStyle(reddish).backgroundColor);
console.log("from a computed style:", window.getComputedStyle(reddish).width);
}, 100);
Run Code Online (Sandbox Code Playgroud)
#reddish {
background-color: #fa5;
width: 100px;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)
<html>
<body>
<div id="reddish"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)