读书人

Python文件处理(一)

发布时间: 2013-09-13 21:12:00 作者: rapoo

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"







读书人网 >perl python

热点推荐