- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Somebody didn't try actually running this code on a machine without the package to see what it outputs:
Admin
Cargo cult programming at its best. Catching exceptions, logging errors, marking sections of code -- all useful if done correctly and with purpose. But this programmer didn't understand either of them and just slapped them on, ticking the boxes off his (mental or even real) checklist.
At some point, someone complained that "Install the package" is not a good error message, so they added a "Please" (as seen by the capitalization of "Install"), again missing the point completely.
Admin
In case anyone thinks that div-0 exceptions somehow make it behave differently:
Admin
"Those comments are just visual noise, they're not making the code any clearer." Your Editor provides syntax highlighting.
Admin
Million dollar question, what is more of a snake, Python programming language or Elizabeth Warren.
Admin
Go back to 4chan, you re not even being original.
Admin
Been waiting for a while to drop that one, have we?
Admin
In other words, if this code (or at least this condition) was something only to be thrown at other developers/devops people around the office (like most Python scripting I see) it's only a bit smelly/lazy?
I miss the days when the TDWTF actually made me think WTF.
Admin
The real WTF is catching Exception instead of ModuleNotFoundError. If an error occurs in numpy this code will ask you to install the already installed package while also hiding the real cause of the error.
Admin
TRWTF is recommending code-driven imports. That's the kind of bad practice that took Knight Capital out of business.
Admin
I dislike stuff like this for a very specific reason. Adding switches to code to detect environment usually means there is a switch later that changes the code path logic will take purely off environment. In other words, you submit code for test in your test environment and everything passes, but in prod it falls over dramatically killing all your processes, because you did not test the prod branch of the switch. In short, you are not deploying what you tested. Stuff like this should not be done at all.
Admin
good exception handling should print phone number of developer
Admin
I knew this dumbass would show up in this thread to let us all know that the language of the day was garbage.
Still haven't actually figured out what he works in. Assembly, maybe?
Admin
I don't see this as a WTF at all. I have had multiple occasions where people don't read install instructions and get stuck on things that are documented. So I have done this after multiple times being told "this doesn't work on my machine" or "it won't run". Hell I even write installation scripts sometimes just so I don't have to deal with things like this one. So seeing this in a code base while sad is probably some poor programmer being fed needing to "help" someone get things running.
In fact the only thing I disagree with on this one is the comment I usually include. "Since people have trouble reading documentation" usually as a comment.
Admin
You, fuckwad.
Admin
What's the result if you run it from the command line? I can't tell if we're seeing strings being printed to stdout/stderr or returned Python values that the interactive mode interpreter is stringifying for us.
Admin
Someone really really really really wants some attention.
Please act quickly, mods. This shit grows faster than black mold if you don't clean it up.
Admin
Shut the fuck up
Admin
For goodness sake some of us read TDWTF to get away from politics. Smh.
Admin
Python 2.7 on Cygwin:
Addendum 2020-02-11 14:38: The key point is that Python's "print" statement is not a function, so in the code in the article, it is being asked to print a tuple consisting of the exception and the string.
Essentially,
print 5
prints the integer 5 to stdout.Admin
In Python 3
print
is a real function, so this code makes a little more sense; it glues all its arguments together (with spaces by default, but who cares about an extra space at the end of a line, right?). It's still the wrongest possible way to do it, but it doesn't have the specific problem you're suggesting.And seriously, Python 3 has been out for over a decade now. If I see Python code here, I'm going to assume it's Python 3 absent clear indications to the contrary.
Admin
Maybe you need to add a spell checker to your "requriements.txt"? :)
Admin
Python 2 is dead. Besides, the code is clearly using Python 3's print function, where the resulting output is sensible.
You seem like the type who refuses to move on from obsolete technology.
Admin
So much butthurt over a joke, you guys are pathetic. Grow up
Admin
It's what I had lying around on my home PC. I installed Py3.6.8 and the result was radically different. I gotta say that that has to have caused some pain when people made the switch unless there were some very good migration tools.
Admin
The 2to3 tool automatically converts it so it was actually completely painless.
Admin
OK, thanks. That's a good thing.
Admin
Amateurs... real Pythonistas import() the result of eval() on user input.
With that, you can do anything.
Admin
@Coyote...: For particularly plural (and unvetted) values of "you".
Admin
Shut the fuck up
Admin
Toxic Bernie bro is toxic.