Qua*_*nic 1 python pep8 indentation multiline continuation
我不得不在今天的 while 条件中添加无关的括号以避免 pep8 投诉:
while not found and not something and \
(time_left is None or time_left > 0):
(one, two, three, four) = self.gimme(timeout=time_left)
Run Code Online (Sandbox Code Playgroud)
我的解决方案:
while (not found and not something and
(time_left is None or time_left > 0)):
(one, two, three, four) = self.gimme(timeout=time_left)
Run Code Online (Sandbox Code Playgroud)
如果我更改了第 2 行缩进,它会抱怨缩进过多或缩进缺失,对于从 W 中的每个缩进到它右侧的 8。
我很烦恼添加无关的括号来满足 pep8,为了几乎没有提高可读性,违背了一般原则。
有任何想法吗?我错过了更好的解决方案吗?
小智 6
我更喜欢在条件语句之后打断长行以提高可读性。例如:
while (
not found and
not something and
(time_left is None or time_left > 9)
):
(one, two, three, four) = self.gimme(timeout=time_left)
Run Code Online (Sandbox Code Playgroud)
我认为这是非常可读的,至少满足我的 pep8 代码样式检查。