So I've been making a Dice Rolling app that takes 3 values from the user (how many dice are rolling, how many faces per die, and whether or not to add or subtract anything from the total), and I've been iterating various measures to make sure that all of the user input values won't cause a crash.
So I've verified that my class-based error checking is working, and that it does exactly what I want it to in reguards to handling exceptions, and now I'm just working on quality of life stuff.
So I have 3 situations that the user can mess up on the input, and for each case that catches an error I want to write it to a pre-existing file and continue so that a different module can read the results and show them to the user. Now, my struggle is the program isn't writing anything to the text file and the file is unreadable according to the system. I triple checked and confirmed that any relative references are correct, all syntax is good, and variable names and stuff matched. The class methods that check for errors work and return the values I want them to. My code is essentially something like:
# unpack the results of case A, B, and C (they are stored in a dict structured like {"is_err": true/false, "err_message": " " for no errors, "error message here" if there is}
err_repo = open("fileA.txt", "a")
exception_caught = False
err_repo.truncate(0) # make sure any previous data is erased
err_repo.write(" ") # makes sure file isn't totally empty for redundancies
if caseA["is_err"] == True:
exception_caught = True #this is returned to the main program to say whether it calls a roll_dice function or not [the user enters a string, the program will convert to an int if exception_caught is False. Otherwise it will read the contents of fileA.txt
err_repo.write(str(caseA["err_message"]))
if caseB["is_err"] == True:
#same as caseA but replacing relevant variables
if caseC["is_err"] == True:
#same as caseA but replacing relevant variables
retval = err_repo.read()
return {"exception_caught": exception_caught, "error_message" = retval}
So what's happening is a little goofy. The file is being written upon, but when I call fileA.read() I get an error saying the file is unreadable. Is there anything extra I need to know about writing to things, please let me know. I've made sure that anything being written to the file is a normal string, not any funky symbols or weirdness. Any help is appreciated here.
Thanks in advance.
PS the error text is "io.UnsupportedOperation: not readable"