作者yjc1 (..........)
看板Python
标题Re: [问题] 判断档案存不存在
时间Tue Jul 22 19:30:06 2008
※ 引述《[email protected] (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
1F:→ bcse:我觉得这篇更不直觉耶 orz 07/22 19:55
2F:推 yzugsr:我想这篇的重点是 exists这个lambda传出字串干麻 07/22 21:36
3F:→ yzugsr:有为FP而FP的感觉.. 07/22 21:36