以下代碼不起作用,且過於冗長且冗長。解決問題的最佳方法是什麼?如何刪除具有多個擴展名的文件
if os.path.exists('*.obj'):
os.remove('*.obj')
if os.path.exists('*.dll'):
os.remove('*.dll')
if os.path.exists('*.exe'):
os.remove('*.exe')
if os.path.exists('*.manifest'):
os.remove('*.manifest')
if os.path.exists('*.pch'):
os.remove('*.pch')
if os.path.exists('*.lib'):
os.remove('*.lib')
if os.path.exists('*.rsp'):
os.remove('*.rsp')
if os.path.exists('Makefile'):
os.remove('Makefile')
也許對http://codereview.stackexchange.com – embert
後寫一個函數? – unlimit
因爲當'os.path.exists'和'os.remove'開始使用glob模式時? –