import os if os.path.isdir(path): print "it's a directory" elif os.path.isfile(path): print "it's a normal file" else: print "it's a special file(socket,FIFO,device file)"
判断文件是否存在
1 2 3 4 5 6
import os >>> os.path.exists('d:/assist') True >>> os.path.exists('d:/assist/getTeacherList.py') True