Re: [問題] 判斷檔案存不存在
※ 引述《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
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章