[Tutor] Introduction - log exercise

Antonio de la Fuente toni at muybien.org
Thu Nov 19 00:06:26 CET 2009


* Christian Witts <cwitts at compuscan.co.za> [2009-11-18 09:53:15 +0200]:

> Date: Wed, 18 Nov 2009 09:53:15 +0200
> From: Christian Witts <cwitts at compuscan.co.za>
> To: Antonio de la Fuente <toni at muybien.org>
> CC: Python Tutor mailing list <tutor at python.org>
> Subject: Re: [Tutor] Introduction - log exercise
> User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
> Message-ID: <4B03A7EB.9 at compuscan.co.za>
> 
> 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: cwitts at compuscan.co.za
> 
> 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.disclaimer at compuscan.co.za or 0861 514131.
> 
> National Credit Regulator Credit Bureau Registration No. NCRCB6
> 
> 

-- 
-----------------------------
Antonio de la Fuente Martínez
E-mail: toni at muybien.org
-----------------------------

... ich bin in einem dusenjet ins jahr 53 vor chr ... ich lande im
antiken Rom ...  einige gladiatoren spielen scrabble ... ich rieche
PIZZA ...


More information about the Tutor mailing list