看板 Python 關於我們 聯絡資訊
※ 引述《qrtt1.bbs@bbs.cs.nctu.edu.tw (null)》之銘言: : ※ 引述《kenduest (小州)》之銘言: : > 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') ............... 這樣倒不如直接寫 print ('not exist', 'exists')[os.path.exists("aaa")] -- 在 python 裡寫 obscue code 不是好風格. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.23.204
bcse:我覺得這篇更不直覺耶 orz 07/22 19:55
yzugsr:我想這篇的重點是 exists這個lambda傳出字串幹麻 07/22 21:36
yzugsr:有為FP而FP的感覺.. 07/22 21:36