Coursework 3

Part A: Display Playlist

Goal: to write a Python program that will read a playlist from a CSV file and display it in the console in the form of a table.

Your goal for this part of the coursework is to write a Python program that can read information about music tracks from a CSV file (i.e.\ a file in Comma Separated Value format) and output the information in an easily readable format. For this part of the coursework you will display the information in a plain text format. (In the next part you will generate an HTML file that can be viewed in a browser.)

Starting with the template file display_playlist.py create a program that satisfies the following requirements:

Further Explanation and Examples

The aim of this coursework is to a Python program in a file called display_playlist.py that includes a function display_playlist(playlist) that will read playlist information from a CSV file, such as the example files geek-music.csv and snake-music.csv, or any file formatted in a similar way, and produce a list of track information that is output to the console. You are provided with an initial version of the display_playlist.py file that contains a useful function for reacing information from a CSV file.

When the display_playlist(playlist) function is run, it should first check whether the given playlist ends in .csv (called the extension of the filename). If so, it should read the playlist data from the file playlist. But if playlist does not end in .csv it should add that extension to get the playlist.csv from which it should read its data. So, to be completely clear, the function should work as follows depending on whether the arguemnt ents in .csv or not:

Which file to read from
playlist argument file to read from
"some-playlist" some-playlist.csv
"some-playlist.csv" some-playlist.csv

The output for a basic solution when display_playlist(geek-music) is run should look something like this:

    TRACK                       ARTIST                    ALBUM                     TIME
    Computer Love               Kraftwerk                 Computer World            7:15
    Paranoid Android            Radiohead                 OK Computer               6:27
    Computer Age                Neil Young                Trans                     5:24
    Digital                     Joy Division              Still                     2:50
    Silver Machine              Hawkwind                  Roadhawks                 4:39
    Start the Simulator         A-Ha                      Foot of the Mountain      5:11
    Internet Connection         M.I.A.                    MAYA                      2:56
    Deep Blue                   Arcade Fire               The Suburbs               4:29
    I Will Derive!              MindofMatthew             You Tube                  3:17
    Lobachevsky                 Tom Lehrer                You Tube                  3:04

Here the TRACK and ARTIST columns are 26 characters wide and I have indented the table by adding a few spaces on the left.
The exact column postioning does not matter, but the data should line up straigt on the left of each column.
I've only given the first 5 playlist tracks. The actual list will be a bit longer.

You can pass this coursework with a basic solution but to gain higher marks you can add further decoration, more sophisticated formatting or additional useful information to your output.

For example, you could get your output to look something like this:

 
    -------------------------------------------------------------------
   | TRACK               | ARTIST        | ALBUM                | TIME |
    -------------------------------------------------------------------
   | Computer Love       | Kraftwerk     | Computer World       | 7:15 |
   | Paranoid Android    | Radiohead     | OK Computer          | 6:27 |
   | Computer Age        | Neil Young    | Trans                | 5:24 |
   | Digital             | Joy Division  | Still                | 2:50 |
   | Silver Machine      | Hawkwind      | Roadhawks            | 4:39 |
   | Start the Simulator | A-Ha          | Foot of the Mountain | 5:11 |
   | Internet Connection | M.I.A.        | MAYA                 | 2:56 |
   | Deep Blue           | Arcade Fire   | The Suburbs          | 4:29 |
   | I Will Derive!      | MindofMatthew | You Tube             | 3:17 |
   | Lobachevsky         | Tom Lehrer    | You Tube             | 3:04 |
    -------------------------------------------------------------------
You may be able to think of other useful information to add.

Files provided for this coursework task: