我有一个脚本通过if语句检查bool然后执行代码.我想要做的是这样做:
if variable a is True, check if b is True and execute code
if variable a is False, execute the same code mentioned before
Run Code Online (Sandbox Code Playgroud)
我目前拥有的简化版本是:
if a:
if b:
print('foo')
else:
print('foo')
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做这个,不需要我写print('foo')两次?
我有几个div垂直排列一个在另一个上面从现在开始我将调用面板.每个面板都具有视口的宽度和高度.所有面板始终具有相同的背景颜色.最初,那种颜色是黑色的.
每个其他面板都是空的,并且充当实际具有内容的面板之间的间隙.订单是这样的:
我想要做的是,当用户向下滚动足以让内容不在视图中的面板时,颜色应该从黑色变为白色.然后,一旦他们滚动到足够第二个面板,内容不在视野范围内,它就应该改回来.
这是我无法弄清楚的部分.到目前为止,我有一个使用我的代码的工作演示:
$(document).scroll(function() {
var viewportHeight = $("html").outerHeight();
var currentY = $(document).scrollTop();
if (currentY % viewportHeight != 0) {
lighten();
} else {
darken();
}
});
function darken() {
$("body").css("background-color", "black");
$(".panel.content").css("color", "white");
}
function lighten() {
$("body").css("background-color", "white");
$(".panel.content").css("color", "black");
}Run Code Online (Sandbox Code Playgroud)
html,
body,
.panel {
width: 100%;
height: 100%;
}
body {
background-color: black;
overflow-y: visible;
overflow-x: hidden;
transition: background-color 500ms linear;
}
.panel {
border: 2px solid …Run Code Online (Sandbox Code Playgroud)我有以下代码:
with open('current.cfg', 'r') as current:
if len(current.read()) == 0:
print('FILE IS EMPTY')
else:
for line in current.readlines():
print(line)
Run Code Online (Sandbox Code Playgroud)
该文件包含:
#Nothing to see here
#Just temporary data
PS__CURRENT_INST__instance.12
PS__PREV_INST__instance.16
PS__DEFAULT_INST__instance.10
Run Code Online (Sandbox Code Playgroud)
但是出于某种原因,current.readlines()每次只返回一个空列表.
代码中可能存在一个愚蠢的错误或拼写错误,但我找不到它.提前致谢.