[Tutor] String matching in 1.5.2 problem
Reggie Dugard
reggie@merfinllc.com
Wed May 7 11:30:06 2003
I believe in 1.5.2 you have to import the string module and use the find
function. Something like
import string
...
if string.find(Y, List1Head) == -1:
...
This should also work fine in python 2.
HTH,
On Wed, 2003-05-07 at 08:03, Daniel Nash wrote:
> I have a python 1.5.2 string matching problem.
>
> I have two lists of email addresses:
>
> list1 = ["dan@NO-SPAM.company.com","fred@NO-SPAM.company.com"]
>
> and another list made up from the contents extracted from an email's headers
> To:,Cc: & Bcc:
>
> list2 =[('', 'support@NO-SPAM.company.com'), ('jim',
> 'jim@NO-SPAM.company.com'), ('',
> 'fred@NO-SPAM.comapny.com')]
>
> I am trying to write a peice of code that will run in python 1.5.2 to return
> true if any element in list1 appears in list2.
>
> In python2 I had this and it served its purpose:
>
> for X,Y in list2:
> for List1Head in List1:
> if Y.find(List1Head) == -1:
> # if false then do nothing
> print "Is NOT Addressed to: ", List1Head
> else:
> print "Is Addressed to: ", List1Head
>
> But I have to make it run on 1.5.2 and I get the following message:
>
> Traceback (innermost last):
> File "MAILIN.py", line 55, in ?
> if Y.find(List1Head) == -1:
> AttributeError: 'string' object has no attribute 'find'
>
> Can anyone tell me how to alter my code to work/improve on my code to only
> return true on an exact match of an email address rather than a sub string
> which allows errors as returning ture for MILE.COM WITHIN SMILE.COM?
>
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Reggie