[Tutor] save configuration of one application.

Luke Paireepinart rabidpoobear at gmail.com
Wed Oct 4 06:43:17 CEST 2006


hok kakada wrote:
> Hi,
>
> Can anybody guide me how to write the code for configure one application?
> For example, I want to set Font and Color for a textbox; later when the 
> application is opened again. the previous font is set.
>
> So, which related function are used to form this feature?
>   
you can make a config.ini file and use that one module that parses ini 
files.
I can't remember what it's called.
configparser I think, but I wouldn't bet my life on it :)

Or you could just write the settings out to a file.
Even better, if you're not making a real-world application and/or you can
trust your users not to muck around with stuff, just make all your 
settings in a class in a module you import.

Eg:

#---- config.py
class Settings(object):
   font = 'Veranda'
   color = 'Black'

#----- program.py

from config import Settings
print Settings.color

#----

Hope that makes sense.
If you choose to go the latter route, keep in mind that  modules are 
compiled to .pyc files upon importation,
so you'll have to remove those anytime you modify config.py or the old 
code will be used instead.
-Luke


More information about the Tutor mailing list