import osif os.path.exists('test.txt'): os.system('taskkill /IM notepad++.exe')
使用os模块,调用windows系统的taskkill命令,假设你打开test.txt的程序名字是notepad++.exe。