proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« Squid Development Projects主页 squid的各种支持补丁和相关小程序 | Main | Firefox 1.5 教育网下载 (windows mac linux * 中文版 English version) »

November 29, 2005

Python 的参数处理和用 gzip module 读取压缩文件

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
http://windtear.net/archives/2005/11/29/000840.html
http://windtear.net/archives/2005/11/29/000840.html

随便写的一个python脚本
结合shell的两个for循环 处理了一大堆已打包的数据

有四点可以提的就是
1. sys module 的参数部分
2. string module 字符串的相关函数
3. gzip 的处理(其实和普通的文件读写调用一样)
4. if 控制结构和缩进

标题定为: Python 的参数处理和用 gzip module 读取压缩文件

#!/usr/bin/python
#
# process lot of gzipped data
# by windtear
#

import sys
import string
import gzip

if len(sys.argv) == 1:
    print "please enter your arg!  e.g.:\n windtear.py /log/ipcn.090000.gz"
    exit
else:
    sf = sys.argv[1]
    if not sf.endswith(".gz"):
        print "arg error!  should be .gz file e.g.:\n windtear.py /log/ipcn.090000.gz"
    else:
        tf = sf[0:5]+sf[10:12]+'/done.txt'
        print 'from '+sf+' to '+tf

        a=gzip.open(sf)
        #a=gzip.open(sf,'rb',6)
        while True:
            b=a.readline()
            if not b: break
            print b
      
        a.close()
本blog WWW

Posted by windtear at November 29, 2005 5:20 PM

Trackback Pings

TrackBack URL for this entry:
http://cgi.windtear.net/cgi-bin/wt-tb.cgi/840

Comments

Post a comment

Remember Me?



我爱网络
2007-12-31 23:51 2007年度 ipcn.org/ipchina.org 总结报告
2007-12-31 00:31 vmware gsx server service
2007-12-31 00:15 squid 对 404 302 缓存的相关问题
2007-12-30 14:24 升级到 MovableType 3.3x 并修改 entry_basename 兼容性
2007-12-30 13:52 [php] realip judge 前面补0的ip格式剔除
2007-12-14 16:34 rm -rf * 系统管理员要排查的定时炸弹
2007-12-13 19:03 山西的宽带运营商太过分了 私自窜改dns解析
2007-12-13 16:35 F5 MIB 再学习 唯一性标记用地址的小bug
2007-12-11 22:15 perl 用Spreadsheet::WriteExcel写了个处理/读写excel的小程序
2007-12-11 13:39 perl 变量转义的问题

本站使用中的任何问题,请与 windtear SPAM windtear SPAM net 联系
Copyright© 1999-2008 Windtear. All rights reserved.
京ICP备05050670号