[Tutor] Re: [Python-Help] Quick question: Is it more efficient to...

Raymond Hettinger python@rcn.com
Tue, 21 May 2002 09:39:12 -0400


Hello Alex,

I like your second approach better.  Rather than reading line by line, try a
full read() into memory and run the regular expression scanners on that
(their C coded internal looping is much faster than looping over lines in
Python).

If you can read directly, try that; however, if you have a complex object
type, Cpickle is the simplest (not necessarily fastest) way of converting
the whole object into a single string for scanning.

Another idea for you is to combine all of your scans into a single regular
expression:  r'(sexy)|(free loan)|(out of debt)'.  If you use the X or
VERBOSE mode, it can be combined without loss of readability.  Combining
them into one allows the re compiler to create a single, efficient state
machine for all of the scans.  Be sure to compile you regular expressions.

I'm not sure about which return codes you should use.

Good luck with your server,


Raymond Hettinger


----- Original Message -----
From: "alex gigh" <cogs2002@hotmail.com>
To: <help@python.org>; <tutor@python.org>
Sent: Tuesday, May 21, 2002 7:13 AM
Subject: [Python-Help] Quick question: Is it more efficient to...


> Hi;
>
> In my mail server, I'm doing some sort of spam detection where I have a
kill
> file which is a list of regular expressions and I have to check that the
> mail doesn't cotain any of these words...
>
> Is it more efficient to (A) check the lines one by one as I receive them
or
> (B) save the whole mail in a file and then check the whole mail with the
> kill file... I have been told that if I use "pickle" I can do some very
> efficient searching...
>
> Which one would be better and why?
>
>
> Also... which number (i.e. 500) do I send back if:
>
> (1) The user is unknown or domain name isn't accepted
> (2) The mail isn't delivered because contains "unaccepted" word
>
>
> Thanks for your help...
>
> Poor CS student trying to finish a mail server before this Thursday!!!
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
>
> _______________________________________________
> Python-Help maillist  -  Python-Help@python.org
> http://mail.python.org/mailman/listinfo/python-help
>