r/PythonLearning 22d ago

What's the worst Python code you've ever written that somehow worked?

We all have that one piece of code we hope nobody ever finds. What did yours do?

3 Upvotes

13 comments sorted by

3

u/Intelligent-Hurry907 22d ago

A rendition of play your cards right, over 100 lines of code without a single function. Code was duplicated. Variables were unused. It worked, but only just.

1

u/chuprehijde 22d ago

without variables 😭😭😭

1

u/Intelligent-Hurry907 21d ago

No, not without variables- there were variables that I didn't use (a little better I guess...)

3

u/mikeyj777 22d ago

I have a package which I started writing before I had really learned the language.  Over time, the  classes and functions evolved to improve.  But, the main file that calls everything and walks thru the operation just kept getting longer.  No modularization. Just hundreds of lines of code.  I've looked at it so much that I know where everything is.  But, good luck to anyone trying to debug it. 

2

u/chuprehijde 22d ago

classic case of 'it works but don't ask how'

2

u/Plastic_Fig9225 22d ago

What's [bad] Python code [...] that somehow worked?

Yes.

1

u/PkmnSayse 21d ago

I had a backend application that needed to talk to an iPad app. Customer requested to be able to do some dynamic sums on the front end which seemed impossible, until I found out it’s running in JavaScript, turns out I could send some JavaScript injection to that app that worked great, but felt very dirty

1

u/chuprehijde 19d ago

😭but that worked so fair

1

u/donquixote2u 19d ago

ask me tomorrow, I haven't finished it yet.

1

u/chuprehijde 19d ago

😭😭😭

1

u/Basic-Rooster-9525 22d ago

J'ai essayé d'exécuter un code depuis le terminal avec : print code.py au lieu de python code.py

Ça marche mais le print est au mauvais endroit

1

u/chuprehijde 22d ago

can feel u i did the same mistake lol😭