作者yungyuc (酷狗喵千代)
看板Python
标题Re: [问题] 判断档案存不存在
时间Wed Jul 23 03:24:42 2008
※ 引述《yjc1 (..........)》之铭言:
: ※ 引述《[email protected] (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