首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python文件处理(一)

2013-09-13 
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"







热点排行