Python文件处理(一)

Python文件处理(1)读取文件解决方案:最简单的就是一次性读取所有的内容放在一个大字符串中 import osdef s

Python文件处理(1)

读取文件

解决方案:

最简单的就是一次性读取所有的内容放在一个大字符串中 

import osdef search_file(filename,search_path,pathsep=os.pathsep):    for path in search_path.split(pathsep):        canditate=os.path.join(path,filename)        if os.path.isfile(canditate):            return os.path.abspath(canditate)        return Nonesearch_path='h://'find_file=search_file('wubi*',search_path)if find_file:    print "File found at %s" % find_fileelse:    print "File not found"