Skip to content

Instantly share code, notes, and snippets.

@ecleel
Created July 17, 2011 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecleel/1087325 to your computer and use it in GitHub Desktop.
Save ecleel/1087325 to your computer and use it in GitHub Desktop.
DictOptions is OrderedOptions copy for python
# DictOptions is OrderedOptions copy for python.
# Basic idea: insted of use dict like this d['key'] = value use it as proprties d.key = value
#
# Examples:
# config = DictOptions()
# config.app_name = "Dictionary Test"
# config.database = "mysql"
# config.server = DictOptions()
# config.server.processes = 5
# ...
#
# Inspired by Ruby OrderedOptions http://goo.gl/zF8HC
class DictOptions(dict):
def __getattr__(self, method_name):
return self[method_name]
def __setattr__(self, method_name, value):
self[method_name] = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment