Question: Write a Python script named sortNames.py that: a. Read in 1 file (filename supplied as argument) and create another file named sortedNames.txt. CPSC254 Prof. Thomas

Write a Python script named sortNames.py that:

a. Read in 1 file (filename supplied as argument) and create another file named

sortedNames.txt.

CPSC254 Prof. Thomas Nguyen Assignment #5 pg. 2

b. If there is not exactly 1 argument, or the file pointed to by the argument doesnt exist or

not readable, print an error message and exit.

c. Input file contains a variable number of names, 1 name per line

d. Each name starts with a first name, an optional middle name or middle initial, and a last

name. You can assume there is no last name modifiers such as Jr, Sr, III, etc. or

compound last name such as du LeBohn. Examples of valid names: Tom Hanks,

Jada Pinkett Smith, Michael J. Fox.

e. In the output file write out all the names, 1 name per line in the following format: last

name first, followed by a comma and a space, followed by first name, followed by a

space, then middle name or initial (if available). The names printed must be sorted in

ascending AZ order by last name. Example outputs: Fox, Michael J., then Hanks,

Tom, then Smith, Jada Pinkett.

f. The argument supplied in part (a) above can be either absolute path or relative path and

the path can contain spaces. Your script must work in all cases as long as the path is

valid (i.e. the file exists).

g. Create the output file sortedNames.txt in the current working directory.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!