Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python: In a file called scourgify.py , implement a program that: Expects the user to provide two command - line arguments: the name of an

Python: In a file called scourgify.py, implement a program that:
Expects the user to provide two command-line arguments:
the name of an existing CSV file to read as input, whose columns are assumed to be, in order, name and house, and
the name of a new CSV to write as output, whose columns should be, in order, first, last, and house.
Converts that input to that output, splitting each name into a first name and last name. Assume that each student will have both a first name and last name.
If the user does not provide exactly two command-line arguments, or if the first cannot be read, the program should exit via sys.exitwith an error message.
Additionally, your program must include:
comments with your name, date, program name, and program purpose.
a main function with if __name__=='__main__': code. See this tutorial from module 5.
Hints
Note that csv module comes with quite a few methods, per docs.python.org/3/library/csv.htmlLinks to an external site., among which are DictReader, per docs.python.org/3/library/csv.html#csv.DictReaderLinks to an external site. and DictWriter, per docs.python.org/3/library/csv.html#csv.DictWriterLinks to an external site..
Note that you can tell a DictWriter to write its fieldnames to a file using writeheader with no arguments, per docs.python.org/3/library/csv.html#csv.DictWriter.writeheaderLinks to an external site..
How to Test
Heres how to test your code manually:
Run your program without any command-line arguments. Your program should exit using sys.exit and provide an error message:
Too few command-line arguments
Create empty files 1.csv,2.csv, and 3.csv. Run your program with python scourgify.py 1.csv 2.csv 3.csv. Your program should output:
Too many command-line arguments
Run your program with python scourgify.py invalid_file.csv output.csv. Assuming invalid_file.csv doesnt exist, your program should exit using sys.exit and provide an error message:
Could not read invalid_file.csv
Run your program with python scourgify.py before.csv after.csv. Assuming before.csv exists, your program should create a new file, after.csv, whose columns should be, in order, first, last, and house.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago