In this chapter, we’re going to look up lines of text from an input file that start with the letters provided by the user. The text will come from an input file that will default to Edward Gorey’s “The Gashlycrumb Tinies,” an abecedarian book that describes various and ghastly ways in which children expire. For instance, figure 7.1 shows that “N is for Neville who died of ennui.”
Our gashlycrumb.py program will take one or more letters as positional arguments and will look up the lines of text that start with that letter from an optional input file. We will look up the letters in a case-insensitive fashion.
$ head -2 gashlycrumb.txt A is for Amy who fell down the stairs. B is for Basil assaulted by bears.
$ ./gashlycrumb.py e f E is for Ernest who choked on a peach. F is for Fanny sucked dry by a leech.