Dictionnary vs Class for configuration
Andrei
project5 at redrival.net
Fri Apr 30 18:04:00 EDT 2004
Famille Delorme wrote on Fri, 30 Apr 2004 19:38:53 +0200:
> The config_section variable is included in each modules (script python) used
> in my program
> (with from config.py import config_section)
I agree with the other posters that unless you know the end users know
Python, you shouldn't configure in Python code (well, unless you have a
system (e.g. GUI) to change it for people who don't know Python).
> And the use is like this
> from conf.py import config_sql
> print config["DATABASE"]
>
> But my master say it's better to do a class like this
> class config :
> def __init__(self, part=="") :
> if (part=="SQL") :
> self.database="nanana"
> self.userdb="bob"
> self.password="*******"
> elif (part=="SCRIPT") :
> self.timetosleep=10
> self.path="/home/script"
> ....
Given the choice between dictionary and class, I would probably take the
dictionary, because it just has more of a "storage" feel to it. OTOH, the
class requires less typing of quotes, which slightly decreases the amount
of time spent on writing the program :).
> We have do only a file for configuration because the administrator is no
> searching for configuration.
> I want know :
> - what is more faster, dictionnary method or class method?
Speed in this case is completely irrelevant.
> - what use more ram memory ?
As long as you don't plan to have dozens of megabytes of configuration, I
don't really see why this would make any difference in your choice neither.
> - if you are administrator, what method you like for configure program ?
GUI, INI file or, if constrained to your two options, the dictionary
approach. Dictionary is probably easier to understand and less intimidating
for non-programmers than the class. With the class being modified by
non-programmers I'd be very afraid they'd break indentation even if they
get the rest of the syntax right.
--
Yours,
Andrei
=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
More information about the Python-list
mailing list