我正在尝试调试(重写?)其他人的 Python/cherrypy Web 应用程序,并且遇到了以下“if”语句:
if not filename.endswith(".dat") and (
filename.endswith(".dat") or not filename.endswith(".cup")
):
raise RuntimeError(
"Waypoint file {} has an unsupported format.".format(
waypoint_file.filename
)
)
我认为这与以下内容相同:
if not A and (A or not B):
如果是这样,那么:
如果
A = False
,那么它减少到if True and (False or not B):
if True and not B
=not B
如果
A = True
,那么它会减少到if False:
即该if
块永远不会执行
我很确定该块的目的if
是警告用户所讨论文件的扩展名不是 也不是.DAT
,.CUP
但在我看来它并没有真正执行该意图。
我认为该if
区块应该是:
if(not .DAT and not .CUP) = if not(.DAT or .CUP)
那正确吗?