我有winapps定制模块。如果软件存在,它会打印详细信息,否则它什么也不会做。
如果没有找到软件,我将如何做一个if语句来打印一些东西?
以下是代码:
with open('output3.txt', 'w') as f:
for item in winapps.search_installed('ledger'):
print(item, end='\n\n', file=f)
发布于 2022-09-20 15:34:54
我建议将匹配的应用程序放到列表中,这样在决定如何处理它之前,您可以很容易地测试它是否为空:
ledger_apps = list(winapps.search_installed('ledger'))
if ledger_apps:
with open('output3.txt', 'w') as f:
print(*ledger_apps, sep='\n\n', end='\n\n', file=f)
else:
print("Software wasn't found.")
https://stackoverflow.com/questions/73789011
复制相似问题