A practical joke with Python

Fun times with Python


I learned Python over a weekend and I’ve built a few small web apps in my spare time using Flask, a microframework. I wanted to play a little joke on my friend because he was teasing me for my love of Python. I started reading through Python’s OS module and I wrote a small script that could make any person go nuts:

import os
while 1:
os.system( “eject /dev/scd0" )

On Linux, everything is treated as a file or a directory. Many devices on a standard computer are treated as files and can be found in /dev/* directory. I knew my friend’s computer had a cd drive and the device would probably be picked up as scd0 so I wrote a small script that opens the cd drive and keeps opening it while the script is running in the background. When my friend went to the washroom, he forgot to lock his computer. I opened a terminal window, downloaded the script, ran it and minimized the window. After getting back from the washroom, my friend was puzzled. He kept trying to put the tray back in the computer and after 2 minutes, he restarted the computer and started raging on the flaws of Linux. A ton of trouble and confusion with 3 lines of code. Pretty fun stuff!

Email me when Arvin Ami publishes or recommends stories