Created
July 17, 2011 07:45
-
-
Save ecleel/1087325 to your computer and use it in GitHub Desktop.
DictOptions is OrderedOptions copy for python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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