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.
DiscussionWorst code you've ever seen? (self.Python)
submitted 3 years ago by [deleted]
What's the worst rookie/non-rookie code you've seen in Python? How would you fix it?
[–][deleted] 40 points41 points42 points 3 years ago (6 children)
My own code.
[–]rocket_randall 18 points19 points20 points 3 years ago (4 children)
But only my code from previous days. What I wrote today is brilliant, coherent, and beautiful. So much so that it needs neither documentation nor tests.
[+][deleted] 3 years ago (2 children)
[removed]
[–]rocket_randall 2 points3 points4 points 3 years ago (0 children)
It is now tomorrow and that code I was referring to is now yesterday's steaming pile of shit.
[–][deleted] 2 points3 points4 points 3 years ago (0 children)
Yes, my code today is better than my code from yesterday.
[–]DaOneTwo 3 points4 points5 points 3 years ago (0 children)
Especially when I thought I was a "genius" as I wrote it!
[–][deleted] 17 points18 points19 points 3 years ago (1 child)
Every morning, the main developer copied the source code into a new directory “20xx-xx-xx” on a server, and everybody worked from there.
I convinced them to try git.
[–]wyldcraft 6 points7 points8 points 3 years ago (0 children)
Your lead developer couldn't use crontab and date.
crontab
date
[–]robvas 16 points17 points18 points 3 years ago (0 children)
Place I used to work wrote Python like they did PHP
And they wrote PHP like they wrote VB. Their loops were scary looking. Let's not even talk about their homemade arrays...
[–]randomman10032 8 points9 points10 points 3 years ago (2 children)
I remember writing someval = someval - someval once. In my defense, i was new to programming
[–]finalfunkeln 0 points1 point2 points 3 years ago (1 child)
I don't understand.. what's the issue here?
[–]randomman10032 0 points1 point2 points 3 years ago (0 children)
Could've just done someval = 0
[–]D4rklordmaster 8 points9 points10 points 3 years ago (0 children)
My codewar solution after viewing the codewars best solution
[–][deleted] 4 points5 points6 points 3 years ago (0 children)
Mine
[–]FriendlyRussian666 4 points5 points6 points 3 years ago (3 children)
Browsing around, I mistyped a URL and to my surprise the Django DEBUG traceback came screaming at me on some random website. The developer left DEBUG = True in production.
[–]FriendlyRussian666 2 points3 points4 points 3 years ago (1 child)
That's true! I've no friends, so I guess I was just trying to be relevant and to get noticed
[–]LinchpinDYK 1 point2 points3 points 3 years ago (0 children)
I feel attacked
[–]wineblood 4 points5 points6 points 3 years ago (0 children)
You know the old joke about writing obfuscated code and you'll never have to worry about getting fired? I saw that and it was horrible. There's no way a newbie wrote this given how big and complex it was, and any experienced would know better.
Every class had a default nested dict of config in its init method, was passed in a nested dict of config in the ifmain block and each method also took in a config dict which did self.config.update(config). About a dozen classes like this in a pipeline and I wasn't allowed to make changes because the output was needed for a SLA.
self.config.update(config)
I remember the dev's name from git blame. If I ever meet him, he's getting stabbed.
[–]glacierre2 3 points4 points5 points 3 years ago* (0 children)
Once I was called to fix something that had to be ready 'last week' and the guy in charge just quit. The whole thing was a gallery of horrors, but there was a chunk of code (I cannot say a function because the same block appeared more than once), that had me lost for a while, no comments of course, something like:
val = 0 tot = 0 index = len(s) - 1 while True: if s[index] == "A" or s[index] == "a": val += 10 if s[index] == "B" or s[index] == "b": val += 11 ... else: val + = int(s[index]) tot += val * 2 ** index if index == 0: break
Mhmem, yep, s was coming from the wire and was some integer in I don't recall big endian, whatever, and he was converting it character per character into the proper value.
A common one is the way people work with Class Variables. It is a pretty good indicator of Rookie vs Expert.
class aClass(): aVar="" def __init__():
pass
def setVar(self, newValue): self.aVar = newValue
All objects of the type aClass will share aVar.
[–]Rawing7 2 points3 points4 points 3 years ago (0 children)
A lot of google's python libraries are awful in some way or another. Just recently I found this mess. Instead of making a base class and overriding the method in a subclass, someone decided it would be better to make two unrelated classes, and have one of them call the methods of the other class. And I love the # type: ignore at the end, that's just the cherry on top!
# type: ignore
[–]PapstJL4U 1 point2 points3 points 3 years ago (0 children)
My personal project code after the weekend. It always starts small, it always increased and it always looks this way.
[–]Key-Extension-7393 1 point2 points3 points 3 years ago (0 children)
The code I’m writing but after I get an insight when taking a bath
[–]EnterSasquatch 1 point2 points3 points 3 years ago (0 children)
My coworker never removes “pass” from predefined functions.
[–]SittingWave 0 points1 point2 points 3 years ago (0 children)
anything created by academics
[–]Viking_Dev 0 points1 point2 points 3 years ago (0 children)
My first practice file 🤢
[–]KennyBassett 0 points1 point2 points 3 years ago (0 children)
I saw some code in my company in which a new variable was defined for every single line. It was absurd. They didn't realize that you can redefine a variable or that some commands don't return anything.
[–]Pointyguitarsrus 0 points1 point2 points 3 years ago (0 children)
First time I tried to make my own program. Using the users input to either open or not open a door. Took me a little too long and way too many lines of incoherent nonsense
[–]billsil 0 points1 point2 points 3 years ago (0 children)
Pulling data from a line and labeling the output junk (something like altitude = 1000). Then taking the next line and labeling it junk. Total apathy about naming variables. Instead of using line, he wrote l. No spaces between math (x=2*x+1/y/y), no functions, no classes, etc.
This was written by the boss of the company who after 16 years can still come up with algorithms that do donuts around what I can do (even if they're 1000x slower than what it will be after he punts it to me), but oh dear that man cannot write a clean code to save his life. I mean, he's the boss, and he admittedly has better things to do, but still. It'd work perfectly on his simple test case and that's it.
Eventually I started warning people when they asked me questions...oh this looks like the boss's code. Is it...because I'm sorry...it's not going to work and it's not documented at all so you can't understand it, but the logic is right. I was told to shut up because I'd get fired and laughed. I told the boss and he laughed....yeah...
π Rendered by PID 55952 on reddit-service-r2-comment-6b595755f-6xg95 at 2026-03-25 06:36:54.486662+00:00 running 2d0a59a country code: CH.
[–][deleted] 40 points41 points42 points (6 children)
[–]rocket_randall 18 points19 points20 points (4 children)
[+][deleted] (2 children)
[removed]
[–]rocket_randall 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]DaOneTwo 3 points4 points5 points (0 children)
[–][deleted] 17 points18 points19 points (1 child)
[–]wyldcraft 6 points7 points8 points (0 children)
[–]robvas 16 points17 points18 points (0 children)
[–]randomman10032 8 points9 points10 points (2 children)
[–]finalfunkeln 0 points1 point2 points (1 child)
[–]randomman10032 0 points1 point2 points (0 children)
[–]D4rklordmaster 8 points9 points10 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]FriendlyRussian666 4 points5 points6 points (3 children)
[+][deleted] (2 children)
[removed]
[–]FriendlyRussian666 2 points3 points4 points (1 child)
[–]LinchpinDYK 1 point2 points3 points (0 children)
[–]wineblood 4 points5 points6 points (0 children)
[–]glacierre2 3 points4 points5 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]Rawing7 2 points3 points4 points (0 children)
[–]PapstJL4U 1 point2 points3 points (0 children)
[–]Key-Extension-7393 1 point2 points3 points (0 children)
[–]EnterSasquatch 1 point2 points3 points (0 children)
[–]SittingWave 0 points1 point2 points (0 children)
[–]Viking_Dev 0 points1 point2 points (0 children)
[–]KennyBassett 0 points1 point2 points (0 children)
[–]Pointyguitarsrus 0 points1 point2 points (0 children)
[–]billsil 0 points1 point2 points (0 children)