simple pattern matching question

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Jun 5 23:18:04 EDT 2002


On 06-Jun-2002 Corey G. wrote:
> Gurus,
> 
> How would I match with an item from a list?  I would imagine something
> this simple would not require a regular expression.
> 
> web_servers=('www01','www02','www03')
> 
>         for server_match in web_servers:
>            if (trap == "Service:"server_match "State:down"):
>             print "found match"
> 
> The comparsion should be: if trap == Service:www01 State:down
> 
> server_match prints "as is, but not from the list".  I tried many 
> combinations but decided to leave the most obviously wrong one.
> 

if trap == ("Service:%s State:down" % server_match):
  print "found match"





More information about the Python-list mailing list