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
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 178 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Sample random, unique string pairs from a list without repetitions walterwhite 1 448 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  trouble reading string/module from excel as a list popular_dog 0 416 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 1,156 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  String to List question help James_Thomas 6 975 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,511 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 914 Feb-23-2023, 02:21 PM
Last Post: sparkt
  convert string to float in list jacklee26 6 1,897 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  Checking if a string contains all or any elements of a list k1llcod3 1 1,094 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  error handler appears to be turned off. How do I turn it back on? jpotter0 0 584 Nov-26-2022, 11:44 AM
Last Post: jpotter0

Forum Jump:

User Panel Messages

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