Python Forum
Create Alert if string from list appears on other list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create Alert if string from list appears on other list
#1
So....

Need to create an alert that will check a log file if a string appears from a list of strings.

I have a list of words, I want my python program to monitor a log file. If any of the words appear to print the line from the log file.

Been pulling my hair out, little left. Please help.

Any advice, would be appreciated but please god no please spare me the "try googling it" responses...

Thank you in advance..
Reply
#2
Use a combination of generator expression and any.

list_of_words = ['A1', 'A2', 'A3']
for line in your_log:
    if any(word in line for word in list_of_words):
        print('ALTERT!')
        print(line)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question about changing the string value of a list element jacksfrustration 4 1,987 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  extract an element of a list into a string alexs 5 3,203 Aug-30-2024, 09:24 PM
Last Post: alexs
  comtypes: how to provinde a list of string to a COM method zalanthas 0 880 Jun-26-2024, 01:27 PM
Last Post: zalanthas
  Strange behavior list of list mmhmjanssen 3 1,536 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  Sample random, unique string pairs from a list without repetitions walterwhite 1 1,759 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  trouble reading string/module from excel as a list popular_dog 0 885 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 2,555 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  String to List question help James_Thomas 6 2,332 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 3,275 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 1,739 Feb-23-2023, 02:21 PM
Last Post: sparkt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020