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

看板Python作者 (酷狗喵千代)時間17年前 (2008/07/23 03:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
※ 引述《yjc1 (..........)》之銘言: : ※ 引述《qrtt1.bbs@bbs.cs.nctu.edu.tw (null)》之銘言: : : 接龍 :P : : import os : : exists = lambda f : (os.path.exists(f) and "exists") or "not exist" : : print exists('test.py') : ............... 這樣倒不如直接寫 : print ('not exist', 'exists')[os.path.exists("aaa")] print "exists" if os.path.exists(f) else "not exist" 都什麼年代了還在用 logic operator? :p Python 3.0: print("exists" if os.path.exists(f) else "not exist") -- back to work. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 164.107.170.191
文章代碼(AID): #18XZFxyI (Python)
文章代碼(AID): #18XZFxyI (Python)