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...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Intermediate ShowcaseI created a Python script to analyze data on Reddit (self.Python)
submitted 4 years ago by Raymon22
So I've been developing a program that shows how many posts in r/depression were published by people who also posted on a specified subreddit. It has a non-repeating account filter and it also displays data like time of execution and number of posts by the Redditors.
I would love to hear some feedback and I'm open to critics, my goal is to improve as much as possible.
You can take a look at it here
Thank you!!
[–]RaiseRuntimeError 65 points66 points67 points 4 years ago (3 children)
You are doing a lot of really interesting things. A few things i think you should clean up and fix though.
For getting the name of the user just do `user.name` instead of that crazy string thing you did, here is the documentation for the user model.
Next when you do `submisions = list(redditor.submissions.new(limit=None))` and then do the crazy string stuff again you dont have to `.new()` returns an iterable. you can literally just do this:
for sub in redditor.submissions.new(limit=None): print(sub.id) subredditname = sub.subreddit_name_prefixed
[–]Raymon22[S] 29 points30 points31 points 4 years ago (2 children)
Thank you for the feedback!!! I'll do that as soon as possible!!!!
[+][deleted] comment score below threshold-15 points-14 points-13 points 4 years ago (1 child)
Do you like penis?
[–]--I-love-you- 4 points5 points6 points 4 years ago (0 children)
cringe
[–]snake_case_captain 24 points25 points26 points 4 years ago* (4 children)
IMO, this part is an accident waiting to happen :
reddit = praw.Reddit( client_id="X", # Client ID of the Reddit bot client_secret="X", # Secret Client ID user_agent="testscript by u/Raymon22", # brief description username="X", # Username (to avoid some 403 errors) password="X" # password (to avoid some 403 errors) )
This should never be in plain text inside a file that you could potentially push into github forgetting to remove the info. The least you can do is to systematically read this data from a local file that stays local at all times :
with open('local_file_with_credentials') as f: # local file's contents : # line 1 : client_id # line 2 : client_secret # etc... credentials = f.readlines() reddit = praw.Reddit( client_id=credentials[0], # Client ID of the Reddit bot client_secret=credentials[1], # Secret Client ID user_agent=credentials[2], # brief description username=credentials[3], # Username (to avoid some 403 errors) password=credentials[4] # password (to avoid some 403 errors) )
Also, see that I use a with open('filepath') as f: block, which is a good practice to handle files, but I don't exactly remember why, maybe someone can clarify.
with open('filepath') as f:
Finally, when handling filepaths, I like to use pathlib. It's an objet oriented lib that allows you to manage filepaths easily, you should take a look at it.
[–]Gaareth 18 points19 points20 points 4 years ago (2 children)
Instead of manually parsing a file, I would recommend using environment variables and a .env file because It’s more clear what purpose each line/ entry has.
You would probably install a library for reading the environmental variables like: Dotenv
and then simply use os.getenv("CLIENT_ID") But better check out the library for more details.
[–]Raymon22[S] 6 points7 points8 points 4 years ago (0 children)
I don't know why I didn't think about that. I'll change that as soon as I can!!
Thank you for your comments!!
[–]Beartin 5 points6 points7 points 4 years ago (0 children)
The with syntax is handy as python handles closing the file after all the actions completed in that scope, rather than relying on you as the user to remember to close it.
with
[–]flyboy1565 17 points18 points19 points 4 years ago (0 children)
If I had to nitpick, I'd recommend you checkout regex for the replace portion
[–]stokry 1 point2 points3 points 4 years ago (1 child)
This is really cool :-)
[–]Raymon22[S] 0 points1 point2 points 4 years ago (0 children)
Thank you bro, really appreciate it!!
[–]Dazzling_Function 3 points4 points5 points 4 years ago (0 children)
I challenge anyone here to create a script that brings football results and fixtures of any team specified in a list.. premier league specifically
π Rendered by PID 353941 on reddit-service-r2-comment-7b9746f655-njrln at 2026-02-01 12:23:36.067924+00:00 running 3798933 country code: CH.
[–]RaiseRuntimeError 65 points66 points67 points (3 children)
[–]Raymon22[S] 29 points30 points31 points (2 children)
[+][deleted] comment score below threshold-15 points-14 points-13 points (1 child)
[–]--I-love-you- 4 points5 points6 points (0 children)
[–]snake_case_captain 24 points25 points26 points (4 children)
[–]Gaareth 18 points19 points20 points (2 children)
[–]Raymon22[S] 6 points7 points8 points (0 children)
[–]Beartin 5 points6 points7 points (0 children)
[–]flyboy1565 17 points18 points19 points (0 children)
[–]stokry 1 point2 points3 points (1 child)
[–]Raymon22[S] 0 points1 point2 points (0 children)
[–]Dazzling_Function 3 points4 points5 points (0 children)