Question: import os class FileHandler: def _ _ init _ _ ( self , filename ) : self.filename = filename def read _ file ( self

import os
class FileHandler:
def __init__(self, filename):
self.filename = filename
def read_file(self):
with open(self.filename, 'r') as file:
data = file.read()
return data
def write_file(self, data):
with open(self.filename, 'w') as file:
file.write(data)
def delete_file(self):
os.remove(self.filename)
def main():
filename = input("Enter the filename: ")
file_handler = FileHandler(filename)
while True:
action = input("Do you want to Read, Write or Delete the file? (R/W/D): ")
if action.lower()=='r':
print(file_handler.read_file())
elif action.lower()=='w':
data = input("Enter the data to write: ")
file_handler.write_file(data)
elif action.lower()=='d':
file_handler.delete_file()
print("File deleted successfully.")
else:
print("Invalid option. Please try again.")
if __name__=="__main__":
mEnsure that your report includes the following:
a) Explanation of the algorithm used in the program.
b) Discussion of coding best practices used in the program.
c) Explanation of any issues encountered during development and how they were resolved.
d) Any other relevant information.ain()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!