Python Exercises lab 7

7.1 Prerequisites and learning outcomes

Before you start you may prefer to have completed lab 6, but before you can do exercises 7.3 and 7.4 it is essential that you have completed lab 5 exercise 5.5.

At the end of this lab you will have:

7.2 Use of Python exception handling

Using a copy of the HTML colouring program you completed for exercise 5.5 (make sure you keep the original intact - you will want to make further modifications of this later) find out what exception is raised if the user inputs the name of a file which doesn't exist. Enhance your copy of this program to trap this exception, and if the file does not exist give the user an option to quit or to try again. This should be done within a loop which can be exit either by the user choosing to quit, or by inputting a file which the program can read from.

7.3 Use of glob to handle multiple files

Take another copy of your original HTML colouring program and this time modify your copy so that you prompt the user for a directory instead of a file, and your program obtains a list of all files in that directory ending in .htm or .html . Next put the main and output parts of your program into a loop so that every file in this list is:

Don't forget to close files after read or write access. The user should only input the required colour once, and all HTML files in this folder should be background coloured the same.

7.4 Use of os, stat and time modules

Write a Python program of which the user can: