As the title says.
Is there a way to make a variable in python that "stays" even you close the file and even restart the computer? I also need to be able to access that variable anytime in the program.
The way im thinking of doing this is by making a txt file and then putting the value of the variable there, but I think its inefficient because I would need to always open the file. Moreover if the file gets deleted, then I also lost the value of that variable.
Here is some pseudocode of what I am thinking to do.
if the file does not exists:
file = open('file.txt','w')
x = 1
file.write(x)
if the file exists:
file = open('file.txt','r')
x = file.read()
<do stuff with the variable x>
file.close()
I want something that I can just instantly access.
P.S. I am planning to convert my python script to a .exe file using pyinstaller, hence I need the code to work even the file has been converted to .exe.