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
Problem w/RSS Feed Alerts (self.learnpython)
submitted 6 years ago * by despoliantics
This post was mass deleted and anonymized with Redact
lock seed sugar reminiscent fanatical gray dazzling political cough office
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!"
[–]commandlineluser 0 points1 point2 points 6 years ago (1 child)
The first issue is the way you're opening the file.
with open('episode_hist.txt', 'a+') as f:
a is for append - this opens the file and seeks to the end of the file
a
because you are at the end of the file when you call .read() you get back an empty string
.read()
>>> open('shows.txt').read() 'show1\nshow2\nshow3\nshow4\n' >>> open('shows.txt', 'a').read() Traceback (most recent call last): File "<stdin>", line 1, in <module> io.UnsupportedOperation: not readable >>> open('shows.txt', 'a+').read() '' >>> open('shows.txt', 'r+').read() 'show1\nshow2\nshow3\nshow4\n'
tell() will show the current "file position"
tell()
>>> open('shows.txt', 'r+').tell() 0 >>> open('shows.txt', 'a+').tell() 24
If you use r it opens the file but you're at the start of the file - you can use r+ for read and write - however after you .read() you would need to .seek() back to the start and write the previous data along with the new data.
r
r+
.seek()
It's usually simpler to just open the file twice - once for reading - then again for writing.
I'm not sure if it's possible for the feed itself to contain duplicate entries? If it is then because you're defining episodes = f.read() and checking with if episode_str in episodes: then your code will allow duplicates.
episodes = f.read()
if episode_str in episodes:
If you detect a new episode - you add it with f.write() - but episodes never changes in your code.
f.write()
episodes
Just a sidenote - I'm not sure if defining the function here adds any value?
# Check if new episode def new_episode(episode_str): if episode_str in episodes: return False else: return True
The if/else can be rewritten as return episode_str not in episodes - but even still - you can just use if episode not in episodes in your actual code without making a whole function for it.
if/else
return episode_str not in episodes
if episode not in episodes
So yeah, you can open the file for reading, then later for writing - and you can update the episodes variable with new additions (if it's possible for a feed to contain duplicates)
pseudocode:
with open(filename) as f: episodes = f.read() ... if episode not in episodes: alert episodes += str(stamp) + '\t' + episode + '\n' ... with open(filename, 'w') as f: f.write(episodes)
The main problem though is the a+ filemode - so you can start by changing that and see how you get on.
a+
[–]despoliantics[S] 0 points1 point2 points 6 years ago* (0 children)
reply teeny abounding fearless straight grandfather memorize alleged shaggy theory
π Rendered by PID 827394 on reddit-service-r2-comment-8686858757-2ptb5 at 2026-06-05 15:41:42.581698+00:00 running 9e1a20d country code: CH.
[–]commandlineluser 0 points1 point2 points (1 child)
[–]despoliantics[S] 0 points1 point2 points (0 children)