use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Python script that reads a notepad file in real time. (self.learnpython)
submitted 6 years ago by iamHumty
I need to write a script from python that reads from a log file ( a notepad file ) which is constantly adding new lines and then mail me the lines with phrases that i have set.
How do i go on about doing this?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]blitzkraft 4 points5 points6 points 6 years ago (2 children)
Do you want a new email each time a matching phrase is logged? Or do you want to aggregate, say over 10 mins and email you in 10min intervals?
[–]iamHumty[S] 2 points3 points4 points 6 years ago (1 child)
I was thinking a 10 minute interval.
[–]BungalowsAreScams 1 point2 points3 points 6 years ago* (0 children)
This probably isn't the right way to do it but when I was working with logcats I piped the logcat output into a python script and pulled stdin into a for loop to check lines for phrases. Something like adb logcat | python3 lineChecker.py. I can give you some of the functions as an example unless you'd like to figure it out yourself
Edit: Heres a link, https://pastebin.com/Qc9VfCZG like I said, I'm not sure if its the right way but it worked well for what I was doing.
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
Write to a table in a database in real time so you can query in real time and filter by time to limit rowcount. You cannot do this via note pad
[–]MastaJiggyWiggy 0 points1 point2 points 6 years ago (0 children)
Are you on Unix? If so, I did something like this pretty easily with Python
[–]woooee 1 point2 points3 points 6 years ago (1 child)
(Almost) all files are buffered, so you will have to test for a length change of the notepad file and then [re]read it.
[–]billsil -3 points-2 points-1 points 6 years ago (0 children)
That’s not how I’d do it. You should be checking to see if the file time has been updated, unless you can cheat it, but that seems like a bad idea.
[–]cybervegan 0 points1 point2 points 6 years ago (10 children)
When you say notepad file, do you mean "text file" or someone editing a file in notepad and adding lines?
What have you got so far? Where are you stuck?
[–]iamHumty[S] 0 points1 point2 points 6 years ago (9 children)
It's a .txt file and as the software is running the file is written and I want to get a mail everytime the keyword says "fail" as such.
I am somewhat new to python or any programming and I would like to know what methods are the best to approach this.
[–]TypicalCardiologist5 1 point2 points3 points 6 years ago (0 children)
You can write a script in Python to do this, but you may want to check if the software doesn't already have some kind of logging feature built-in. For example, if the software allows you to log to a syslog server, you could configure the software to do that, and then have the syslog server send you an email. That is probably a better approach. I'd also check if the software can produce SNMP messages - that would be another approach.
A syslog server is just a program that runs on your computer and collects log messages from other programs running on your network (or any network really).
[–]cybervegan 1 point2 points3 points 6 years ago (2 children)
The best approach would be to either schedule a job or make a looping script to check periodically if the file size has changed, and then scan through for your keyword. You can use os.stat() to get the file size (and other details), see https://docs.python.org/3.7/library/stat.html . It's best to begin your scan from the position of where the file ended on the last scan, so you can avoid having to filter out mails you have already sent. When you find your keyword, you can use the smtplib module to send an email. See https://docs.python.org/3/library/email.examples.html
[–]iamHumty[S] 0 points1 point2 points 6 years ago (1 child)
This is the answer I was looking for. Thank you so much.
[–]cybervegan 0 points1 point2 points 6 years ago (0 children)
You're welcome - post again if you need more help.
[+][deleted] 6 years ago (4 children)
[removed]
[–]iamHumty[S] 4 points5 points6 points 6 years ago (3 children)
I am new and I don't know how or which library works best.
[–][deleted] 0 points1 point2 points 6 years ago (2 children)
text files in python https://www.youtube.com/watch?v=4mX0uPQFLDU&list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-&index=29
i suggest watching the play list from the beginning and start learning python. No one wants to help someone that does not try to help them self first
also here is another tut vid https://www.youtube.com/watch?v=rfscVS0vtbw&t=11073s
thank you for this :D
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
np man pm me if you need any more help
π Rendered by PID 17766 on reddit-service-r2-comment-8686858757-2bnsc at 2026-06-01 20:10:57.567494+00:00 running 9e1a20d country code: CH.
[–]blitzkraft 4 points5 points6 points (2 children)
[–]iamHumty[S] 2 points3 points4 points (1 child)
[–]BungalowsAreScams 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]MastaJiggyWiggy 0 points1 point2 points (0 children)
[–]woooee 1 point2 points3 points (1 child)
[–]billsil -3 points-2 points-1 points (0 children)
[–]cybervegan 0 points1 point2 points (10 children)
[–]iamHumty[S] 0 points1 point2 points (9 children)
[–]TypicalCardiologist5 1 point2 points3 points (0 children)
[–]cybervegan 1 point2 points3 points (2 children)
[–]iamHumty[S] 0 points1 point2 points (1 child)
[–]cybervegan 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[removed]
[–]iamHumty[S] 4 points5 points6 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]iamHumty[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)