Question
Python problem 1. Consider a program that possesses a function that reads information from a file, called read_file() . The read_file function normally intends to
Python problem
1. Consider a program that possesses a function that reads information from a file, called read_file(). The read_file function normally intends to return a list containing pieces of information from the file that is read.
If the file reading fails (i.e. raises an exception), what should the read information function do?
A.Catch the exception and return None in the finally clause.
B.Catch the exception and print a message in the finally clause.
C.Do nothing (dont catch the exception)
D.Catch the exception and print a message in the except clause.
E.Catch the exception and return None in the except clause.
Problem 2
In writing networked programs, we utilized sockets to connect to other computers. We switched from the use of sockets to the use of what we called pseudo-files.
(a) What purposes did these pseudo-files serve, in terms of improvements over just writing and reading directly to and from sockets?
(b) Why did we call flush() when writing to pseudo-files?
Problem 3
When writing programs that access file systems, we opted to use particular libraries from the Python Standard Library like pathlib.
(a) Why did we use pathlib over just using open() or os.path on files? Give two specific reasons.
(b) What was the purpose of the method iterdir of the Path class from the pathlib library?
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