Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 5

1,491 bytes added, 08:07, 9 September 2017
LAB REVIEW
= LAB REVIEW =
# xWhat is the purpose of a file object?# xWrite a Python command to '''open''' the text file called '''customers.txt''' for read-only operations.# xWrite Python code to efficiently store the contents of the file in question #2 as a large string (including new-line characters) called '''customer-data'''.# Write Python code to store the contents of the file in question #2 as a list, removing the new-line characters.# What is the purpose of closing an open file? Write a Python command to close the file opened in question #2.# Write the Python command to confirm you successfully closed the '''customers.txt''' file in question #5. What is the returned status from that command to indicate that the file has been closed?# What is the difference between opening a file for writing data as opposed to opening a file for appending data?# Write a Python command to open the file '''customer-data.txt''' for writing data.# Write a Python command to save the text: '''customer 1: Guido van Rossum''' to the opened file '''customer-data.txt'''# Briefly explain the process of using a loop to write a list as separate lines within an open file.# What is the purpose of '''handling''' exception errors?# Write a Python script to prompt a user for the name of the file to open. Use exception error handling to provide an error message that the specific file name (display that exact name) does not exist; otherwise, open the file for reading and display the entire contents of the file (line-by-line).
13,420
edits