Im relatively new to coding. I want to program a kind of menu in python and it is working very good besides one thing. My code looks like this
def menu()
n=input()
match n:
case 1:
alphabet = readdata(alphatxt)
… # do couple of things with alphabet
menu()
case 2,3,4 etc.
The function readdata looks like this:
def readdata(dataname)
with open(dataname, ‘r’) as data:
return data.read()
My intention is that if I press 1 for case 1 it would read the contents of “alphatxt” into alphabet.
At the end of case 1 I want to go back to the start of the menu. Now I want to change the alphatxt, I go in the editor, write something else in it and close it. I now would assume that if I press 1 again, that it would now take the new contents of alphatxt, but that is not the case, until I restart the program, it is using the old contents of alphatxt, but why?
I tried to put all files I need to read right at the beginning of the function, assuming that it would update, as soon as I call the function recursive back, but that is also not the case.Even when the function is over and I call the function completely new, it doesnt update
Ben Bensen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.