What is the simplest human readable configuration file format?

Posted by Juha on Programmers See other posts from Programmers or by Juha
Published on 2012-03-26T14:11:29Z Indexed on 2012/03/26 17:38 UTC
Read the original article Hit count: 298

Filed under:
|
|
|

Current configuration file is as follows:

mainwindow.title = 'test'
mainwindow.position.x = 100
mainwindow.position.y = 200

mainwindow.button.label = 'apply'
mainwindow.button.size.x = 100
mainwindow.button.size.y = 30

logger.datarate = 100
logger.enable = True
logger.filename = './test.log'

This is read with python to a nested dictionary:

{
  'mainwindow':{
    'button':{
      'label': {'value':'apply'},
       ...
  },
  'logger':{
     datarate: {'value': 100},
     enable: {'value': True},
     filename: {'value': './test.log'}
  }, 
  ...    
}

Is there a better way of doing this? The idea is to get XML type of behavior and avoid XML as long as possible. The end user is assumed almost totally computer illiterate and basically uses notepad and copy-paste. Thus the python standard "header + variables" type is considered too difficult.

The dummy user edits the config file, able programmers handle the dictionaries. Nested dictionary is chosen for easy splitting (logger does not need or even cannot have/edit mainwindow parameters).

© Programmers or respective owner

Related posts about python

Related posts about design-patterns