代码如下:
#encoding=utf-8 print '中国' #在Python的搜索路径中寻找文件 import sys,os class Error(Exception):pass def _find(pathname, matchFunc=os.path.isfile): for dirname in sys.path: candidate = os.path.join(dirname, pathname) print candidate if matchFunc(candidate): return candidate raise Error("Can't find it") def findFile(pathname): return _find(pathname) def findDir(path): return _find(path,os.path.isdir) print findFile(r'_bsddb.pyd')
打印结果如下:
中国
F:\workspace\StudyPy\src\basic\_bsddb.pyd
F:\workspace\StudyPy\src\_bsddb.pyd
D:\Python27\DLLs\_bsddb.pyd
D:\Python27\DLLs\_bsddb.pyd