well, my script is so simple ! nothing complicated #!/usr/bin/python #
import re, sys a=open('/home/john/data/file_input.tmp', 'r') b=open('/home/john/data/file_output', 'w') aa=a.readlines() n=0 for L in aa: # I split every line because i only need what's after the ":" # the email comes in the form "field : value" in 17 lines La=L.split(':') n=n+1 # 18 is the last line & it is an empty line that comes with every email # so i quit there. if n==18: sys.exit() # second line is a time value like this one "18:20:45" # i don't need the ":" but i need the numbers elif n==2: # as usual i remove the \n & put a ; in its place and that happens # at the third element La3=re.sub('\n',';',La[3]) # i gather the time value also there is no need for : in between La123=La[1]+La[2]+La3 b.write(La123) # any other line is treated equaly like this # i only replace \n by ; else: La1=re.sub('\n',';',La[1]) b.write(La1) # a little secret : this little script helps me load data from mail to a mysql database by converting it into ; separated values :) On Tue, Apr 1, 2008 at 2:09 AM, Chris Fuller <[EMAIL PROTECTED]> wrote: > Every five lines of the raw email, the headers, or the body? > > A text file is just data. You can navigate however you like, but you need > to > choose a model, to give it some structure for you to work with, > Navigating > around at the byte level is probably going to be tedious, error prone, and > not very useful anyway. Choosing five lines at a time is probably not > going > to be much better. There's no particular reason it can't be ten lines, or > two, unless you pick a model that > > Maybe we could help more if you showed us what this "original script" is. > We > can help you pick a better model if the one implicit in your script isn't > working for you. > > Also, you should probably reply to the mailing list. > I'll be more careful about the reply-to field from now on. > > Cheers > > > On Monday 31 March 2008 14:43, you wrote: > > the mail module seems interesting. but what I was thinking of some way > > that would work on only five lines then moves to the next five lines & > so > > on ... is that possible ? is there a way of navigating a text file ? > > process the line that we want, maybe delete it or maybe add text to it > & > > then save & close the file ? > > > > > > On Fri, Mar 28, 2008 at 1:08 PM, Chris Fuller > > <[EMAIL PROTECTED]> > > > > wrote: > > > The email and mailbox modules might help you out. Multiple email > > > messages will probably parse as an mbox format mailbox. > > > > > > http://docs.python.org/lib/module-email.html > > > http://docs.python.org/lib/module-mailbox.html > > > > > > Cheers > > > > > > On Friday 28 March 2008 03:14, linuxian iandsd wrote: > > > > good morning everybody ! > > > > > > > > I have scripted a small program to parse a 5 lines email message as > it > > > > comes in to my inbox (this is handled by procmail & here is a > wonderful > > > > intro to it : > http://linuxfocus.org/English/November1997/article8.html) > > > > > > > > so every email is being parsed & information is extracted from it. > > > > > > > > but sometimes two or more emails come in at once so the input file > that > > > > > > my > > > > > > > python script has to parse is more than five lines !! my question is > > > > how > > > > > > do > > > > > > > i effeciently manage this from within my original script. > > > > > > > > thanks > > > > > > _______________________________________________ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor