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. b. If there
Write a Python script named sortNames.py that:
a. Read in 1 file (filename supplied as argument) and create another file named sortedNames.txt.
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.
This code will be run on Ubuntu terminal.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
