python--文件处理范例
2015-12-30 14:12
447 查看
import os,os.path,string dir="D:\\curl\\data" if (os.path.exists(dir)==False): print "not exist,create" long_time=[] def func(a): if a >=10: return True else: return False def func2(a): if len(a.strip())==0: return -1 b=a.rstrip('\n') c=string.atof(b) return c os.chdir(dir) for file in os.listdir(dir): #print file with open(file,'r') as f: content = f.readlines() if content!= []: data=map(func2,content) long=filter(func,data) if long!=[]: long_time.append(long) f.close() with open(r"d:/curl/long_time.txt",'w') as f: print long_time for data in long_time: f.write(str(data[0])) f.write("\n")
读取某个文件夹下所有文件
相关文章推荐
- [LeetCode]题解(python):088-Merge Sorted Array
- Python标准库10 多进程初步 (multiprocessing包)
- 笨方法学Python(11-15)
- Use Visual studio 2010 build Python2.7.10
- [LeetCode]题解(python):086-Partition List
- [LeetCode]题解(python):083-Remove Duplicates from Sorted List
- [LeetCode]题解(python):082-Remove Duplicates from Sorted List II
- Python标准库09 当前进程信息 (os包)
- [LeetCode]题解(python):081-Search in Rotated Sorted Array II
- [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II
- Python 2.1 函数的调用
- [LeetCode]题解(python):079-Word Search
- [LeetCode]题解(python):078-Subsets
- [LeetCode]题解(python):077-Combinations
- Python 第二章 函数
- [LeetCode]题解(python):076-Minimum Window Substring
- caffe 如何调用python层
- Caffe学习系列(13):数据可视化环境(python接口)配置
- python AES-16位加密解密功能实现
- Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)