• (nodebb)

    Somebody didn't try actually running this code on a machine without the package to see what it outputs:

    >>> try:
    ...  x = 1/0
    ... except Exception as e:
    ...  print(e,"\nPlease wobble")
    ... 
    (ZeroDivisionError('integer division or modulo by zero',), '\nPlease wobble')
    
  • Foo AKA Fooo (unregistered)

    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.

  • (nodebb)

    In case anyone thinks that div-0 exceptions somehow make it behave differently:

    >>> try:
    ...  import Frobble as frob
    ... except Exception as e:
    ...  print(e,"\nPlease install the Package")
    ... 
    (ImportError('No module named Frobble',), '\nPlease install the Package')
    
  • Ed Lin (unregistered)

    "Those comments are just visual noise, they're not making the code any clearer." Your Editor provides syntax highlighting.

  • (nodebb)

    Million dollar question, what is more of a snake, Python programming language or Elizabeth Warren.

  • Anonymous (unregistered) in reply to Mr. TA

    Go back to 4chan, you re not even being original.

  • Dude (unregistered) in reply to Mr. TA

    Been waiting for a while to drop that one, have we?

  • MiserableOldGit (unregistered) in reply to Steve_The_Cynic

    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.

  • (nodebb)

    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.

  • Raj (unregistered)

    TRWTF is recommending code-driven imports. That's the kind of bad practice that took Knight Capital out of business.

  • Kattman (unregistered)

    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.

  • bvs23bkv33 (unregistered)

    good exception handling should print phone number of developer

  • tbo (unregistered) in reply to Mr. TA

    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?

  • Ugot2BkidNme (unregistered)

    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.

  • Rodd Tundgren (unregistered) in reply to Mr. TA

    You, fuckwad.

  • Jonathan (unregistered) in reply to Steve_The_Cynic

    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.

  • Jonathan (unregistered) in reply to Mr. TA

    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.

  • Shut the fuck up (unregistered) in reply to Mr. TA

    Shut the fuck up

  • code_goddess (unregistered) in reply to Mr. TA

    For goodness sake some of us read TDWTF to get away from politics. Smh.

  • (nodebb) in reply to Jonathan

    Python 2.7 on Cygwin:

    steve@KYLATH ~
    $ python ./blof.py
    (ImportError('No module named Frobble',), '\nPlease install the Package')
    

    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.

  • Paul Z (unregistered) in reply to Steve_The_Cynic

    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.

  • Jake (unregistered)

    Maybe you need to add a spell checker to your "requriements.txt"? :)

  • (nodebb) in reply to Steve_The_Cynic

    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.

  • (nodebb)

    So much butthurt over a joke, you guys are pathetic. Grow up

  • (nodebb) in reply to Zacrath

    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.

    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.

  • (nodebb) in reply to Steve_The_Cynic

    The 2to3 tool automatically converts it so it was actually completely painless.

  • (nodebb) in reply to Zacrath

    OK, thanks. That's a good thing.

  • Coyote... (unregistered)

    Amateurs... real Pythonistas import() the result of eval() on user input.

    With that, you can do anything.

  • WTFguy (unregistered)

    @Coyote...: For particularly plural (and unvetted) values of "you".

  • Shut the fuck up (unregistered) in reply to Mr. TA

    Shut the fuck up

  • Diane B (unregistered)

    Toxic Bernie bro is toxic.

Leave a comment on “Install Your Package”

Log In or post as a guest

Replying to comment #:

« Return to Article