CodeSOD: All Thumbs

This post was originally published on this site

The Daily WTF

Nick L supports a hardware system that should autodetect a USB drive when inserted, and then load a config file off of it. This fairly simple task is made more complicated by the freelancer they hired to solve the problem, who has someā€¦ interesting approaches to writing Python.

thumb_name = [] while thumb_name == []: sleep(1) thumb_name = os.listdir(“/media/update”) ser.write(bytes(“usb drv not detectedr”,’UTF-8′)) print (“test”) print (thumb_name) print (“test”) thumb_name_pure = thumb_name[0]

This code’s attempt to confirm whether or not the USB drive has been inserted is to attempt to list the directories at the mount point. The result of this is stored in a variable named thumb_name, which importantly, isn’t the name of the drive, but is the list of files in the folder. This whole thing is gated in a while loop that requires thumb_name to actually hold entries, so I hope that the drive eventually mounts,

To read the full article click on the 'post' link at the top.