tw.bbs.comp.lang.python
  Home FAQ Contact Sign in
tw.bbs.comp.lang.python only
 
Advanced search
July 2008
motuwethfrsasuw
 123456 27
78910111213 28
14151617181920 29
21222324252627 30
28293031    31
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
tw.bbs.comp.lang.python Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  xyz         


Author: xyz
Date: Jul 22, 2008 06:13

xyz,xyz
no comments
  xyz         


Author: xyz
Date: Jul 22, 2008 06:13

xyz,xyz
no comments
  xyz         


Author: xyz
Date: Jul 22, 2008 06:13

xyz,xyz
no comments
  xyz         


Author: xyz
Date: Jul 22, 2008 06:13

xyz,xyz
no comments
  xyz         


Author: xyz
Date: Jul 22, 2008 06:13

xyz,xyz
no comments
  Re: [問題] 判斷檔案存不存在         


Author: ..........
Date: Jul 22, 2008 04:30

※ 引述《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
no comments
  Re: [問題] 判斷檔案存不存在         


Author: null
Date: Jul 21, 2008 18:34

※ 引述《kenduest (小州)》之銘言:
> ※ 引述《jeffreychen.bbs@ptt.cc》之銘言:
>> 請問一下
>> 我想判斷aaa檔名的檔案存不存在
>> 在python要如何寫呢
> 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')

--
FP-like 的寫法
Show full article (0.89Kb)
no comments
  xyz         


Author: xyz
Date: Jul 21, 2008 14:30

xyz
no comments
  xyz         


Author: xyz
Date: Jul 21, 2008 14:30

xyz
no comments
  exyz         


Author: xyz
Date: Jul 21, 2008 14:30

xyz
no comments
 
1 2 3 4 5 6 7 8 9