Dictionnary vs Class for configuration

From: Famille Delorme (fadelorme_at_free.fr)
Date: 04/30/04


Date: Fri, 30 Apr 2004 19:38:53 +0200

Sorry if this discussion are already submited, but I don't find anything
really interresting for me.
And sorry for my bad english, it is not my native language.

I wrote a program in Python for a school project and I am in trouble.
I have make a Python script called conf.py. This file contains dictionnarys
for configuration like this:
config_sql = {
                "DATABASE" : "nanana",
                "USERDB" : "bob",
                "PASSWORD" : "********"
                    }
config_script = {
                "TIMETOSLEEP" : 100
                "PATH" : "/home/script"
                }
The config_section variable is included in each modules (script python) used
in my program
(with from config.py import config_section)
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"
        ....

and the use like this
    from conf.py import config
    cfg=config("SQL")
    print cfg.database

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?
 - what use more ram memory ?
 - if you are administrator, what method you like for configure program ?

Note:
    * the class will not have methods, it is not necessary.
    * the program is composed of several modules which import
config_section.

Thank you for futures answers,
3Zen



Relevant Pages

  • RE: Help...I hosed my system trying to apt-get dist-upgrade
    ... Setting up python... ... dpkg: dependency problems prevent configuration of rhythmbox: ... Package python is not configured yet. ...
    (Debian-User)
  • Re: Dictionnary vs Class for configuration
    ... Python, you shouldn't configure in Python code (well, unless you have a ... > - what is more faster, dictionnary method or class method? ... As long as you don't plan to have dozens of megabytes of configuration, ... non-programmers I'd be very afraid they'd break indentation even if they ...
    (comp.lang.python)
  • Re: Import and execfile()
    ... pickle with the readability of Python. ... instead of nested dicts, etc. ... I'd suggest that you should have all your configuration ... In the case where you config files are parsed by the ...
    (comp.lang.python)
  • How should multiple (related) projects be arranged (structured) and configured so that they can shar
    ... I was hoping that someone could help me out with my python programming ... a common base package hierarchy (as is standard practice in the java ... PYTHONPATH, or other configuration tricks? ...
    (comp.lang.python)
  • Re: Best way to store config or preferences in a multi-platform way.
    ... This project will store most of its actual data in a shared-database, but I have a small amount of user specific data that I need to be stored like configuration or preferences for example, the list of databases that the program should connect to. ... On Unix this might be a .file, on windows this could be in the registry, or an ini file or an xml file in ProgramData or AppData or something. ... Python has modules available for accessing INI-files, ...
    (comp.lang.python)