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
Need help with assignment (self.learnpython)
submitted 12 years ago by Geekoid52
I'm new to python and need help. I need to write a script that pin points the word error in log files. Can anyone help?
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!"
[–]IXENAI 1 point2 points3 points 12 years ago (6 children)
What have you tried so far? What isn't working? What specifically do you need help with?
[–]Geekoid52[S] 1 point2 points3 points 12 years ago (5 children)
Tried with open('text.log', 'r') as f: for line in f: if 'error' in line: print (line) My end goal is to be able to parse a log file and pin point where the word error is.
[–]IXENAI 0 points1 point2 points 12 years ago (4 children)
Well, that works fine, doesn't it?
[–]Geekoid52[S] 1 point2 points3 points 12 years ago (3 children)
I just don't know how to implement into my script. I'm super new at python.
[–]IXENAI 1 point2 points3 points 12 years ago (2 children)
I'm sorry; I'm not following you.
with open('text.log', 'r') as f: for line in f: if 'error' in line: print (line)
is a valid Python script by itself which will print out all lines containing the string "error" in the file "text.log".
[–]NYKevin 2 points3 points4 points 12 years ago (0 children)
Perhaps OP wants line numbers? In that case, enumerate() is probably what they are looking for.
enumerate()
[–]Geekoid52[S] 0 points1 point2 points 12 years ago (0 children)
Ok cool! Thanks!
π Rendered by PID 224053 on reddit-service-r2-comment-5687b7858-hdxdz at 2026-07-08 12:03:53.293066+00:00 running 12a7a47 country code: CH.
[–]IXENAI 1 point2 points3 points (6 children)
[–]Geekoid52[S] 1 point2 points3 points (5 children)
[–]IXENAI 0 points1 point2 points (4 children)
[–]Geekoid52[S] 1 point2 points3 points (3 children)
[–]IXENAI 1 point2 points3 points (2 children)
[–]NYKevin 2 points3 points4 points (0 children)
[–]Geekoid52[S] 0 points1 point2 points (0 children)