python应用
来源:互联网 发布:心目中最好av作品知乎 编辑:程序博客网 时间:2024/06/05 03:58
域名过滤:从daminFile文件按行读取,将符合规则的域名行记录下来。
import osimport re#input the file pathdaminFile = raw_input('File path:\n')#result file pathresultFile = daminFile+'_rs.txt'fileRead = open(daminFile, 'r')fileWrite = open(resultFile, 'w')#set the ruleregex = ur'^[\w]{1,5}\.(com|net|org)$'#get each linefor eachLine in fileRead:print eachLineif 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,shutildirPath = ''def walk(path):for fileobj in os.listdir(path):if fileobj == '.svn':shutil.rmtree(os.path.join(path, fileobj))else:filepath = path+'//'+fileobjisDir = os.path.isdir(filepath)if isDir:print filepathwalk(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 ' + dirPathgetInput()if __name__=='__main__':getInput()
- python应用
- python 应用
- python应用
- python 应用
- python应用
- python应用
- Python应用广泛
- Embedded Python应用小结
- Python 应用发布技术
- python set 简单应用
- python mail脚本应用
- Python 串口设备应用
- python的实例应用
- python 应用实例
- python 装饰器 应用
- Envisaged python 应用框架
- Python Socket 简单应用
- Python 应用发布技术
- C++的XML编程经验――LIBXML2库使用指南
- 基于AIR实现的Android程序
- ios6 支持旋转问题
- 事务的原子性,一致性,隔离性,持久性
- ErgodicFile
- python应用
- 软件测试
- LockHandle
- C#实现大文件拷贝
- 编程技能和做员工的技能——哪个更重要?
- 日本衰落,中国收回钓鱼岛已成定局
- MySqlHelper
- EXP-00003问题解决(解决导出表中有CLOB或BLOB字段的情况)
- threadmanage