python应用
2012-09-21 12:23
239 查看
域名过滤:从daminFile文件按行读取,将符合规则的域名行记录下来。
第一次将python用于实际需求:想注册一个域名,到最新过期的域名里挑,每天数十万的记录,人工挑选是不可能的,用python先挑选出长度5位以内,com/net/org 域名。
不算注释和空行,12行代码,python真的很省事。
----------------------------------分割线---------------------------------------
去除项目目中中.svn文件 :
import os import re #input the file path daminFile = raw_input('File path:\n') #result file path resultFile = daminFile+'_rs.txt' fileRead = open(daminFile, 'r') fileWrite = open(resultFile, 'w') #set the rule regex = ur'^[\w]{1,5}\.(com|net|org)$' #get each line for eachLine in fileRead: print eachLine if re.match(regex, eachLine): fileWrite.write('%s' % eachLine) fileWrite.close() fileRead.close()
第一次将python用于实际需求:想注册一个域名,到最新过期的域名里挑,每天数十万的记录,人工挑选是不可能的,用python先挑选出长度5位以内,com/net/org 域名。
不算注释和空行,12行代码,python真的很省事。
----------------------------------分割线---------------------------------------
去除项目目中中.svn文件 :
import os,sys,stat,shutil dirPath = '' def walk(path): for fileobj in os.listdir(path): if fileobj == '.svn': shutil.rmtree(os.path.join(path, fileobj)) else: filepath = path+'//'+fileobj isDir = os.path.isdir(filepath) if isDir: print filepath walk(filepath) def getInput(): dirPath = raw_input('Enter the dir path(eg:"e:/test"):\n') if os.path.isdir(dirPath): walk(dirPath) else: print 'there is not a directory named ' + dirPath getInput() if __name__=='__main__': getInput()
相关文章推荐
- python基础之“换行符”的应用
- python3中import语句(搜索路径的应用)
- Python起步之面向对象初步应用(烤地瓜)
- lesson1:Python 判断表达式应用
- 【python学习】django安装,第一个应用
- python典型应用场景、domo及模板之一-----------配置&日志
- Python Web应用选型实例
- 在Linux上使用Python和Flask创建你的第一个应用
- python 应用thrift---- thrift的监控fb303 -
- python中stack在实际中的简单应用之平衡符号
- python轻量级爬虫学习笔记 之 urllib的应用
- 序列截取应用:python3中字符串通过循环每次把位于最后的一个字符砍掉
- python 偏函数应用
- Python(应用) — Excel操作(一)
- python的list,dict,tuple比较和应用
- python中lxml的应用
- HTML+CSS+python+qtwebkit打造跨平台桌面应用(二)
- Python 语言及其应用 Chapter_4_Note_1 推导式
- Python数据结构之图的应用示例
- 用python创建一个简单的restful风格的web服务应用