I have a python/pygame program that reads data from a settings file at the start of the program and writes out (changed) settings at the end of the program. This settings file is in the same (app.folder) directory as the main.py program. Everything works fine when running the program in a Python environment but when I compile it using Pygbag the file is read quite happily but I cannot write back to it at the end of the program.
My reading code is:
main_dir = os.path.split(os.path.abspath(__file__))[0]
settingsTxt = os.path.join(main_dir,"settings.txt")
...
...
with open(settingsTxt,"r") as settings:
setting = settings.readline()
while setting != "":
line = setting.split()
if line[0] == "sheep":
no_sheep = int(line[2])
sheep_count = no_sheep
if line[0] == "dog_bark":
if line[2] == "True":
dog_bark = True
else:
dog_bark = False
if line[0] == "bleat":
if line[2] == "True":
bleat = True
else:
bleat = False
setting = settings.readline()
My writing code is:
with open(settingsTxt,"w") as settings:
setting = "sheep = {}n".format(sheep_count)
settings.write(setting)
setting = "dog_bark = {}n".format(dog_bark)
settings.write(setting)
setting = "bleat = {}n".format(bleat)
settings.write(setting)
The setting file is in the home directory …/freddie (as is main.py) which, when running the program in the browser is reported as:
/data/data/freddie/assets
which I cannot find either in the home directory or in the build directory created by pygbag.
Why can I not write back in the compiled version of the program whereas I can when running it in a python environment? Is it because my write code is wrong, is the directory created by pygbag read only, is the file being created in some unknown directory or is it something else?
If it is not possible to write a file in compiled python/webassembly is there some other way I can store what is, essentially, localStorage data?
Any help/suggestions would be gratefully received!