PyCat

Indices and tables

Background

Linux has a handy tool for displaying and concatenating files together on the command line. The tool is called, cat, and a quick write-up about it can be found on Wikiepdia here.

The cat command is commonly called with just one filename as the only argument to it (much to the irritation of purists). In this instance, all cat does is echo the lines in the file, to the terminal.

Exercise

Implement a reduced version of the cat command using Python (i.e. pycat).

Start by only including support for echoing the contents of the file to the screen. The user should be able to type a command like the following to get it to work:

pycat.py filename

After you have the initial shell of the program, implement additional functionality of the cat command (such as actually concatenating multiple files together).

Hints

Review the sys package for details on using sys.argv as a simple way to get the command line arguments.

Solution

When you are ready to see one possible solution to just echoing the contents of the file to the terminal, try this file