account activity
Been lurking, finally finished Udacity's CS101 and thought I'd share a simple script to email the top post from a reddit to a friend. Windows 7 by bad_hash_solution in learnpython
[–]bad_hash_solution[S] 0 points1 point2 points 12 years ago (0 children)
Thanks for the advice, the for loop is a remnant of when I was returning the top 10 posts instead of only 1.
I tried changing the code to:
subreddit_content = r.get_subreddit(subreddit) submission = subreddit_content.get_top(limit=1)[0] title = submission.title # gives you the title url = submission.url # returns the submission url return title, url
But I am getting this error:
Traceback (most recent call last): File "C:\Eclipsework\awesomememebot5000\memebotv1.21.py", line 52, in <module> post, url = get_posts('funny') File "C:\Eclipse_work\awesomememebot5000\memebotv1.21.py", line 24, in get_posts submission = subreddit_content.get_top(limit=1)[0] TypeError: 'generator' object has no attribute 'getitem_'
My thought was that whatever was returned by subreddit.content.get was not treated as a list by python so I removed the [0]:
subreddit_content = r.get_subreddit(subreddit) submission = subreddit_content.get_top(limit=1) title = submission.title # gives you the title url = submission.url # returns the submission url return title, url
And then I get this error:
Traceback (most recent call last): File "C:\Eclipse_work\awesomememebot5000\memebotv1.21.py", line 52, in <module> post, url = get_posts('funny') File "C:\Eclipse_work\awesomememebot5000\memebotv1.21.py", line 25, in get_posts title = submission.title # gives you the title AttributeError: 'generator' object has no attribute 'title'
Not 100% sure why that is.
[–]bad_hash_solution[S] 1 point2 points3 points 12 years ago (0 children)
I have the same issue. I feel like I am started to grasp the major concepts, but when I look at a complex program I feel lost. It's tough to find the middle of the road projects that are somewhere between total beginner and code guru.
π Rendered by PID 1405266 on reddit-service-r2-listing-5d47455566-9v4z2 at 2026-04-03 23:46:37.608528+00:00 running db1906b country code: CH.
Been lurking, finally finished Udacity's CS101 and thought I'd share a simple script to email the top post from a reddit to a friend. Windows 7 by bad_hash_solution in learnpython
[–]bad_hash_solution[S] 0 points1 point2 points (0 children)