python function question.
Question Description
Write a function (call it get_fh) that receives two arguments: 1). A file name 2).
How to open a file for reading or writing (“r”, or “w”) in Python. The
purpose of this function is to open the file name passed in, and pass
back the file handle. I can call this function like this:
fh_in = get_fh(file_2_open, “r”) or
fh_out = get_fh(file_2_write, “w”)
**When using open(), make sure to use try .. except .. except if the open was not successfu the program should raise the right Excpetion(it should raise an IOError for when the file cannot be opened, and raise a ValueError when the wrong argument was passed for the opening mode, e.g. “rrr” instead of “r”). We will test for things like a file that does not exist for opening, or the wrong open mode, e.g. mode=’rrr’. See open for more information. All opening and closing of files in your program should use the get_fh function.
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."