I want to reload my JSON after my text file is updated by reopening the text file.
import json
with open('np.txt') as np:
np_data = np.read()
np_list=json.loads(np_data)
def reopen_file():
print("reloading")
with open('np.txt') as np:
np_data = np.read()
np_list=json.loads(np_data)
y=1
while(y==1):
#np.flush()
#reopen_file()
x=input("input: ")
print("your input is" +x)
if(int(x)==1):
print(np_list)
y=input("continue?: ")
reopen_file()
print(np_list)
I update the text file before entering the value for 'y'(continue?), but the output remains the same. (I am editing the file manually)
np.txt:
{"a":"1",
"b":"2",
"c":"3",
"d":"4",
"e":"5",
"f":"6",
"g":"7",
"h":"8",
"i":"9"}