Dark theme

Issue: Getting it working
Key skill: problem decomposition


Let's look at a simple example. We're not really even going to look at the code, which is fine. Download this zip file into a directory, unzip it, and open a command prompt/terminal in the same directory. The zip contains three files:

  1. HelloWorld.py – the standard Python "Hello World";
  2. HelloWorld.bat – a file to let us easily run the program on Windows;
  3. HelloWorld.sh – a file to let us easily run the program on Macs and Linux.
A brief intro is needed to the two last files, known as "shell scripts": most operating systems provide some kind of command line shell – a text-driven interface that allows you to type commands to the computer and acts as an environment in which you can run programs. For many years, these underlay the whole of the graphical elements of operating systems. In Windows, this is the command line, or "DOS prompt" (named after DOS). Mac and Linux come with a wide variety, accessed through the terminal application, but the csh or bash are the common defaults. In each case, it is possible to write and run "shell scripts" – short files containing sets of commands you'd like to run. One advantage of this is that it is easier for a user to execute a shell script than type complicated commands. For example, in Windows, where these are called "bat" files, you just double-click the file, or go to the directory at the command prompt and type the name without the extension to run the script. On Macs/Linux, these are ".sh" shell scripts.

So, our bat and sh scripts should run the HelloWorld.py file. At the command prompt, run the right shell script by typing HelloWorld. The right shell script for the operating system should execute, but if it doesn't, add the .sh or .bat file extension. Note that if we just double-click the files in a file explorer, the command line will flash open and then disappear, making it hard to read what's happening, so we'll run by typing for the moment.


Ok, so, it doesn't run. This is a shame. The question is, can we fix it? Let's decompose the problem. What we need to do is break down the problem into its component parts, and work out a test for each. What are the component parts here? See if you can write a list before going on to the next part. Order them by how potentially tricky you think they'd be to test and solve. Here's a start:

  1. Our typing of the shell script name.
  2. The python script that is run.
  3. ?
  4. ?
  5. ?


  1. Start
  2. The problem
  3. Decomposing the problem <-- next
  4. Testing the parts
  5. Solving the issues 1
  6. Solving the issues 2
  7. Final points