Can't write Option values to Prc file

I’ve been trying to save player options (keybinds, etc.) to a prc file by first constructing two lists of configVariableStrings, and then using the following bit of code:

print("running save")
writer = open("options.prc", "w")
for i in textOps:
    writer.write(i.get_name() + ' ' + i.get_string_value() +'\n')
for i in keybinds:
    writer.write(i.get_name() + ' ' + i.get_string_value()+ '\n')

Bizarrely, no matter what I do, the existing prc file is not modified, nor is a new file even created, assuming it would create one in the directory this script is, as opposed to
Does anyone know of any “proper” methods of saving configVariables?

Hmm, it’s actually a regular python object for file system input and output.

A quick test showed that it works.

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    def __init__(self):
        file = open('config.prc', 'w')
        file.write("config " + "param" + "\n")

app = MyApp()

If I’m understanding correctly that this script is run by the program in “”, then I would expect to find the resulting file in the directory of the latter, not the former, I believe.

Things are getting more bizarre… I guess writing files doesn’t work when running inside visual studio, but it does work when using panda3d’s python.exe or ppython.exe… and yet, this somehow causes a crash when I right-click → open with → python… which, is just peachy because that’s the only way of running it I don’t know how to view the console output.

Edit: the version of python that’s crashing is indeed ppython, making this all the more confusing, as running save() with the app opened via cmd works just fine…

The initial issue turned out to be that file-saving seems to be more-or-less interrupted when running python through visual studio.
After that, I discovered that running via right-clicking → open with → python leads to the file write failing due to insufficient permissions.

1 Like