Answered step by step
Verified Expert Solution
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 commandline 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 commandline arguments, or if the first cannot be read, the program should exit via sysexitwith an error message.
Additionally, your program must include:
comments with your name, date, program name, and program purpose.
a main function with if namemain: code. See this tutorial from module
Hints
Note that csv module comes with quite a few methods, per docs.python.orglibrarycsvhtmlLinks to an external site., among which are DictReader, per docs.python.orglibrarycsvhtml#csvDictReaderLinks to an external site. and DictWriter, per docs.python.orglibrarycsvhtml#csvDictWriterLinks 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.orglibrarycsvhtml#csvDictWriter.writeheaderLinks to an external site..
How to Test
Heres how to test your code manually:
Run your program without any commandline arguments. Your program should exit using sysexit and provide an error message:
Too few commandline arguments
Create empty files csvcsv and csv Run your program with python scourgify.py csv csv csv Your program should output:
Too many commandline arguments
Run your program with python scourgify.py invalidfile.csv output.csv Assuming invalidfile.csv doesnt exist, your program should exit using sysexit and provide an error message:
Could not read invalidfile.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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started