Re: [問題] 判斷檔案存不存在

看板Python作者時間17年前 (2008/07/22 10:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/5 (看更多)
※ 引述《kenduest (小州)》之銘言: > ※ 引述《jeffreychen.bbs@ptt.cc》之銘言: > > 請問一下 > > 我想判斷aaa檔名的檔案存不存在 > > 在python要如何寫呢 > import os.path > if os.path.exists("aaa") : > print "exist" > else: > print "not exist" 接龍 :P import os exists = lambda f : (os.path.exists(f) and "exists") or "not exist" print exists('test.py') -- FP-like 的寫法 -- ▄▄▄▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄ <telnet://bbs.cs.nctu.edu.tw> █▄▄▄▄█ █ ▄▄▄▄▄█ Player: qrtt1 ▄█▄▄▄▄█ ▄▄▄█ █▄▄▄▄▄ From: ce13088.ce.ntu.edu.tw ☆ 次世代BS2 ☆ 可申請個人板 150MB 相簿 http://pic.bs2.to 交大資訊人 250MB
文章代碼(AID): #18XJzV00 (Python)
文章代碼(AID): #18XJzV00 (Python)