"Nick Burgess" <burgess.n...@gmail.com> wrote
How do I make this code print lines NOT containing the string 'Domains'?


Don't use regex, use in:

for line in log:
    if "Domains" in line:
        print line

This does not work...

if re.search != (r'Domains:', line):

Because you are assigning a tuple containing a string and a line of text to a name which is currently bound to a function object (re.search) which is not a sensible thing to do since you lose access to the search function. If you really do need to use regex you probably want:

    if not re.search(r'Domains', line):
          print line

But if it is a simple string you are searching for regex is overkill and probably slower than using in.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to