Load values from a Python module. Example modue ``config.py``:: DEBUG = True SQLITE = { "db": ":memory:" } >>> c = ConfigDict() >>> c.load_module('config') {DEBUG: True, 'SQLITE.DB': '
(self, path, squash=True)
| 2744 | self._virtual_keys = set() |
| 2745 | |
| 2746 | def load_module(self, path, squash=True): |
| 2747 | """Load values from a Python module. |
| 2748 | |
| 2749 | Example modue ``config.py``:: |
| 2750 | |
| 2751 | DEBUG = True |
| 2752 | SQLITE = { |
| 2753 | "db": ":memory:" |
| 2754 | } |
| 2755 | |
| 2756 | |
| 2757 | >>> c = ConfigDict() |
| 2758 | >>> c.load_module('config') |
| 2759 | {DEBUG: True, 'SQLITE.DB': 'memory'} |
| 2760 | >>> c.load_module("config", False) |
| 2761 | {'DEBUG': True, 'SQLITE': {'DB': 'memory'}} |
| 2762 | |
| 2763 | :param squash: If true (default), dictionary values are assumed to |
| 2764 | represent namespaces (see :meth:`load_dict`). |
| 2765 | """ |
| 2766 | config_obj = load(path) |
| 2767 | obj = {key: getattr(config_obj, key) for key in dir(config_obj) |
| 2768 | if key.isupper()} |
| 2769 | |
| 2770 | if squash: |
| 2771 | self.load_dict(obj) |
| 2772 | else: |
| 2773 | self.update(obj) |
| 2774 | return self |
| 2775 | |
| 2776 | def load_config(self, filename, **options): |
| 2777 | """ Load values from an ``*.ini`` style config file. |