Python script can't save and open (file.txt)

I made a game which is saving and reading properties (lifes, level etc.). It works when I have my game on my desktop, but when I create an instalation file and then when I install this game on (C:/Program Files/MyGame) location - it doesn’t work. I use Python script to save and read properties from (file.txt). I think it might be because of this line, but I have no idea what is wrong and how to figure out it: open (path + “file.txt”…
Maybe I should use something else than (path)? I tried to manually change value in (file.txt) in folder with the game but there was “Access denied” window. Maybe Blender also have no access to open, wright, and save any value in any file in this folder when game is installed?

Please help me if you have an idea what could I do to fix this problem.

PS: sorry for my english

Microsoft made the “C:\Program Files” directory and its sub-directories non-writable for security reasons. You need admin privileges to copy files there. For this reason the Windows version of Blender uses the “C:\Users\USERNAME\AppData\Roaming\Blender Foundation\Blender” directory for storing user preferences and installed add-ons. For an example on how to access the “AppData\Roaming” directory with Python, see this post:

So where should I paste this script from link?

In my script I have:

if load_key.positive:
with open(path + “save.txt”, ‘r’) as readfile:
myfile = readfile.read()
clean_lines = myfile.split(’,’)

So in which place i need to paste it?:

import os dir_path = ‘%s\Example\’ % os.environ[‘APPDATA’] if not os.path.exists(dir_path):
os.makedirs(dir_path)
file_path = ‘%sexample.db’ % dir_path sqlite3.connect(file_path)

And this is complited script? Or must I replace something somewhere? Im just starting with Python and I don’t know how it works yet.