Best way to update a settings file?

John Salerno johnjsal at gmailNOSPAM.com
Sun Apr 13 23:11:18 EDT 2008


I'm thinking about writing a small script that will update an xml file 
with whatever game settings the user enters. I imagine that the user 
will have a single-screen GUI application with several different 
settings, like this:

CROSSHAIRS   ON
LOCATION     ON
HEALTHBAR    OFF
etc.....

These settings will somehow be toggleable with an ON/OFF button, or 
something.

Anyway, I can think of two ways to do this:

1. After the user chooses his settings and clicks the Save button, 
Python reads all the settings from the GUI application and updates 
*every* entry in the xml file (whether it has changed or not).

2. After the user chooses his settings and clicks the Save button, 
Python reads all the settings from the GUI application, compares these 
settings to those in the xml file, and updates only the ones that have 
been changed.

Now, #2 seems, at first glance, like the more efficient option, because 
you are only updating what needs to be updated, and leaving the rest alone.

However, I wonder if the extra step of comparing all the settings from 
the user input and the xml file will end up taking longer than just 
simply rewriting all the settings.

Probably neither method will take much longer than the other, but I'm 
asking more from a good design/efficiency standpoint. Which of these two 
methods is the better way, or is there perhaps another way I'm not 
thinking of?

Thanks!



More information about the Python-list mailing list