Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

You are being asked to create simple function to check for the existence of files in your environment using a TRY...EXCEPT block. The list of

You are being asked to create  simple function to check for the existence of files in your environment using a TRY...EXCEPT block.   The list of files to check will be given.  You need to create program to check files and output whether each file exists or not to an output file.  You must ensure that the program runs and does not show any crashes to the user.    

Grading

The assignment will be graded by instructor criteria list below.  You may develop the code in any Python editor, but the code must run in Cengage environment.  There is no automatic grading for this assignment.  You will need to submit the assessment in Blackboard. 

 


 

 

What you need to know

 

Read list of files from file: file_list.txt

The list of files is below, create and save this file in your python environment.  This is text file with 9 lines and no header. 

users.csv

suspended_accounts.csv

accidents.csv

ace_awards.csv

travel_costs.csv

business_expenses.csv

daily_visits.csv

class_list.csv

users_backup.csv

 

Check to see if the file exists or not in your environment.

Create simple function to attempt to open each file, and then if file opens then the file exists.  If the file does not open, then catch the exception, and pass back result that the file does not exist. 

You can read the file above into a list and then iterate through the list to check for existence of each file. Below is sample print statements to check status of development. 

 

 

Output file name and exist status to CSV file

Output the list of file names and exist status to comma delimited file with header names: filename and exists.  Write to a file output_list.csv with sample output as below. 

filename,exists

users.csv,True

suspended_accounts.csv,False

accidents.csv,False

ace_awards.csv,False

travel_costs.csv,False

business_expenses.csv,False

daily_visits.csv,False

class_list.csv,True

users_backup.csv,False


 

 

Grading Criteria

This will be fully graded by the instructor.

 

image.png 

# 1 2 3 4 5 Criteria Read list of files from file_list.txt a) Open file_list.txt for reading b) Read files into list for processing as needed. c) Close file or use context manager. Create function that generically checks for file exists. a) Create simple function that takes filenames as input. b) Function return True if the file exists, and False if it does not exist. c) Use try except logic to catch the file not found error. Create output_list.csv with filename and status. a) Open output file, output_list.csv b) Write a header with "filename, exists" c) Write one row for each file, list the filename and whether the file exists by a comma. separated d) Close the file or use the context manager. Test Strategy and Test Case The program is expected to provide the output as above with no program crashing. Correct spelling is required. Comments Add comments using doc string at the top of the program to give overview of what the function and what the program does and any assumptions that you are making, and program flow. The comments at the top of each file must have your name as author and the date. Correct spelling is required. Points 20 20 20 20 20

Step by Step Solution

3.50 Rating (140 Votes )

There are 3 Steps involved in it

Step: 1

Source Code The required program is written as follows Save the program as codepy Test Case The ... 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_2

Step: 3

blur-text-image_3

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

Auditing a risk based approach to conducting a quality audit

Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg

9th edition

9781133939160, 1133939155, 1133939163, 978-1133939153

More Books

Students explore these related Programming questions

Question

List the advantages of using GAS.

Answered: 3 weeks ago