我有一个名为“列表”的文件,我需要打印某些信息,但不是整个文件。我的档案如下:
pool
pool/return
pool/home
pool/home/audits
pool/home/audits/2013
pool/home/audits/2014
pool/home/exchanges
pool/home/term
pool/transfers
我需要打印“/home/”下的所有内容,除了“audits/”部分。下面是我的代码:
^{pr2}$我得到以下信息:
pool
pool/return
pool/home
pool/home/exchanges
pool/home/term
pool/transfers
但我只需要打印:
pool/home/exchanges
pool/home/term
您必须检查“/home”是否一致,以及“home/audits”是否一致:
条件
if '/home' and not 'home/audits' in line:
get已转换为
if True and not 'home/audits' in line:
因为只要填充字符串,
bool('/home')
(或bool('any string')
)始终为真相关问题 更多 >
编程相关推荐