Hi Tracy,

This config stuff comes up quite a bit in Python coding. One of the
simplest approaches is to use classes as you were thinking, but not to
bother with instantiation:

# config.py

class defaults:
  load_warning=2
  load_critical=4
  disk_warning=90
  disk_critical=95

class djutil01(defaults):
  report_load = (2, 4)
  report_disk = (90, 25)

# end config.py

Then to use it:

# myprog.py

import config

  # if you want a more readable call that using getattr() directly,
  # and/or a better error message
def get_config(serverName):
   container = getattr(config, serverName, None)
   if container is None:
       raise KeyError, 'No config for server name %r' % serverName
   return container

...

print get_config(someServerName).report_load
# or
server = get_config(someServerName)
print server.report_load
print server.load_warning


That's all there is to it.

-Chuck

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to