* Christian Witts <[email protected]> [2009-11-18 09:53:15 +0200]:

> Date: Wed, 18 Nov 2009 09:53:15 +0200
> From: Christian Witts <[email protected]>
> To: Antonio de la Fuente <[email protected]>
> CC: Python Tutor mailing list <[email protected]>
> Subject: Re: [Tutor] Introduction - log exercise
> User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
> Message-ID: <[email protected]>
> 
> How I would process it:
> 
> from sys import argv, exit
> import gzip
> 
> if __name__ == '__main__':
>    try:
>        fIn = gzip.open(argv[1])
>    except IOError:
>        exit('Cannot open file specified.\n')
> 
>    fOut = open('outputFile', 'a')
> 
>    datablock = []
>    discard = False
>    for line in fIn:
>        if line.strip():
>            if line.strip() == 'foo':
>                discard = True
>            else:
>                datablock.append(line)
>        else:
>            if discard:
>                datablock = []
>                discard = False
>            else:
>                fOut.write(''.join(datablock))
> 
>    fIn.close()
>    fOut.close()

I've borrowed a couple of things from your script.
It is educative for me to see different ways of solving the problem.
Thank you.
> 
> -- 
> Kind Regards,
> Christian Witts
> Business Intelligence
> 
> C o m p u s c a n | Confidence in Credit
> 
> Telephone: +27 21 888 6000
> National Cell Centre: 0861 51 41 31
> Fax: +27 21 413 2424
> E-mail: [email protected]
> 
> NOTE:  This e-mail (including attachments )is subject to the disclaimer 
> published at: http://www.compuscan.co.za/live/content.php?Item_ID=494.
> If you cannot access the disclaimer, request it from 
> [email protected] or 0861 514131.
> 
> National Credit Regulator Credit Bureau Registration No. NCRCB6
> 
> 

-- 
-----------------------------
Antonio de la Fuente Martínez
E-mail: [email protected]
-----------------------------

... ich bin in einem dusenjet ins jahr 53 vor chr ... ich lande im
antiken Rom ...  einige gladiatoren spielen scrabble ... ich rieche
PIZZA ...
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to