import ast

# FileHandler reads and writes data to a text file.
class FileHandler():
    def __init__(self, path):
        self.file_path = path
    
    # read_data reads text file and returns dictionary.
    def read_data(self):
        dic = {}
        with open(self.file_path, 'r') as file:
            s = file.read()
            dic = ast.literal_eval(s)
        return dic
    
    # write_data writes dictionary to a text file.
    def write_data(self, dic):
        with open(self.file_path, 'w') as file:
            file.write(str(dic))