Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Best way to update a settings file?

Reply
Thread Tools

Best way to update a settings file?

 
 
John Salerno
Guest
Posts: n/a
 
      04-14-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!
 
Reply With Quote
 
 
 
 
John Nagle
Guest
Posts: n/a
 
      04-14-2008
John Salerno wrote:
> 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.


You can't write into the middle of an XML file effectively; any field
that has changed length won't fit. You generally have to create a new
XML file.

Read this on how to replace a file with a new one, as an atomic operation:

http://blogs.msdn.com/adioltean/arch...28/507866.aspx

If you really want to update files in place, use a database, like
SQLite. If you find yourself rewriting big files for minor changes,
switch to a database. For small files, just rewrite the whole thing.

John Nagle
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update On The Windows Phone 7 Update Update Lawrence D'Oliveiro NZ Computing 2 02-25-2011 08:03 AM
Settings.settings file with settings for multiple regions donet programmer ASP .Net 3 11-20-2009 03:05 PM
Open Question: Settings for your Canon 10D - Best Way? JCL Digital Photography 1 01-06-2005 08:00 AM
Open Question: Settings for your Canon 10D - Best Way? JCL Digital Photography 1 01-05-2005 02:49 PM
Best way to load/store web site settings in database Max ASP .Net 2 12-08-2003 10:39 PM



Advertisments