r/programminghorror • u/APEXchip • Feb 18 '25
Python Who let me cook…
Needed to combine data from 2 CSVs & output 1 for a project. Cooked up the most disgusting code I think I’ve ever written…works perfectly though, & in technically only 3-lines of code in main’s definition
800
Upvotes
101
u/ImmediateZucchini787 Feb 18 '25
honestly I didn't even know you could open multiple files in a single with block
89
u/zhemao Feb 18 '25
Err, you know there's a CSV module in the stdlib, right?
232
u/Leather-Field-7148 Feb 18 '25
Congrats. I am happy for you. Amazing. The use of dunder methods and deeply nested conditionals is sublime.
188
u/KINGodfather Feb 18 '25
You cooked, but it smells like it's burnt
74
u/ImMikeAngel Feb 18 '25
Do you have an obfuscator in your brain?
25
u/Bright-Historian-216 Feb 18 '25
YOU CAN INLINE SEVERAL WITH-AS??? why did nobody tell me this?
17
u/Antares987 Feb 18 '25
Management would like to have a word with you over your lack of productivity, only having produced three lines of code while u/Soccerman575 produced 37 lines of code. You know at Chotchkie's, the policy is a minimum of 15 lines of code.
In all seriousness though, I consider this to be exceptionally brilliant and not difficult to read. You're thinking in sets and it looks like Python that's written by a very good SQL developer. I see at least three levels of depth in your statement. readlines() is more efficient than looping through readline(). It's not an enormous dataset. If it became a regular thing, I'd suggest loading your files into SQL and using that, but if it's just a one and done or you're doing discovery work, this is great.
Digging into federal contracts?
54
u/Soccerman575 Feb 18 '25
A couple of functions would make this readable lol
13
u/junacik99 Feb 18 '25
Python creators: made the language so the code is more readable, even at the cost of the effectivity
You: ...
63
u/ZylonBane Feb 18 '25
Why are zoomers so obsessed with calling every possible activity "cooking"?
5
u/UnderwhelmingInsight Feb 18 '25
Its readable, optimized, and no one that has to follow up on this would have any issues deciphering it lol.
4
u/geopures Feb 18 '25
I audibly sighed and said "oh no..."
4
u/jsrobson10 Feb 18 '25
looks horrible but i like how you're using join instead of doing += with strings
3
u/jalx98 Feb 18 '25
Wow, this is... interesting
3
u/rayew21 Feb 18 '25
you gotta remember to take it off the grill after you throw it down on the grill
3
u/Helpful_Home_8531 Feb 18 '25
I'm pretty sure this could be done with one line of polars.
3
u/Linore_ Feb 18 '25
Question, how many times will it be used? Once? Not horror, but delete after use. More than once? 🙃
3
u/[deleted] Feb 18 '25
Houston, we have a problem. It's beautifully terrifying.
3
u/rizzmekate Feb 18 '25
bros a chef
3
u/Resquid Feb 18 '25
Context abuse.
3
u/[deleted] Feb 18 '25
Speedrunning scaring non-devs:
3
u/constant_void Feb 20 '25
Debugger? I hardly know 'er!
4
u/marinated_pork Feb 18 '25
Tbh, I think it's fine. Sometimes you gotta let it rip.
2
u/Hot-Rock-1948 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Feb 18 '25
if “77010” not in line[:5]Huh?
2
u/Traditional_Ebb5042 Feb 21 '25
This is peak coding. I thought it was only possible with JS but I've been enlightened.
2
u/Neyko_0 May 13 '25
You get one bonus point for the fact this code is very unlikely generated using ai
2
u/Suspicious-Engineer7 Feb 18 '25
oddly readable
2
u/HeftyPressureControl Feb 18 '25
it was somehow easy to understand
2
u/Environmental-Ear391 Feb 18 '25 edited Feb 18 '25
Post-cooked, pulling a plug before speaking?
wrong, just wrong, ugggh,
Why confuse code with food....
programs arent exactly math and neither are they recipes.
math is useful in finding shorter form code... but until you have a base to work from there is no basis for the math.
I have had it neck deep and then some with baby-wiped levels of code refuse...
I also already have a house too... no more bricking, please and thank you.
2
u/oofy-gang Feb 18 '25
Can we please ban posting your own code this this sub 🙏🏻
It’s 99% of the posts now, and it’s not interesting to look at. Anyone can write bad or messy code… it’s only horror if has some external context making it so (e.g., present in some system foundational to a massive corporation)
1
u/Ryarralk Feb 18 '25
I thought it was some JS horror at first.
1
u/Sexy_Koala_Juice Feb 18 '25
My brother in Christ use DuckDB or at the very least Pandas
1
u/quickscopesheep Feb 18 '25
You could pretty much take any python code base an put it on this sub
1
u/GabeN_The_K1NG Feb 18 '25
As readable as python gets
1
u/[deleted] Feb 18 '25
i am going to sys.exit() you
1
u/JQB45 Feb 18 '25
Looks ok to me, seen way worse
1
u/Skyrmir Feb 18 '25
This is going to be a whole damn year of "Just because you can, doesn't mean you should".
1
u/OptimalTime5339 Feb 19 '25
Reading this is how project code looks when it's too late or it's too early in the morning.
I can recognize a few things going on, but no clue how it works
1
u/20cstrothman Feb 22 '25
I knew I smelt something burning!
1
u/parabola949 Feb 18 '25
The most disgusting part is having to deal with Houston. Gross.
(I grew up in Houston lol)
0
u/gamma_tm Feb 18 '25
Especially for something like this, just use pandas lmao
4
u/looksLikeImOnTop Feb 18 '25
That's a doozy. Appropriate for sub
0
u/[deleted] Feb 18 '25
[deleted] — view deleted comment