我有一个 if 语句,如下所示
if (not(fullpath.lower().endswith(".pdf")) or
not (fullpath.lower().endswith(tuple(settings.imageExtensions)))) :
问题是这些都不起作用,如果文件以 .pdf 或其他扩展名之一结尾,它会进入 if 函数。 做这个的最好方式是什么? 仅供引用,我不能将 .pdf 放在元组中
请您参考如下方法:
你想根据DeMorgan's laws切换到和
if not(fullpath.lower().endswith(".pdf")) and not (fullpath.lower().endswith(tuple(settings.imageExtensions))) :
换句话说,以下是等价的
not A and not B == not (A or B)
