From f04531a601e6d5bb940fa1b2e83127da1d5bdeb5 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Mon, 4 Mar 2013 13:37:48 -0500 Subject: [PATCH] * Parameters: Added _append_() and _prepend_() methods. --- params/params_flat.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/params/params_flat.py b/params/params_flat.py index b08a79d..fd2be62 100644 --- a/params/params_flat.py +++ b/params/params_flat.py @@ -260,6 +260,21 @@ class Parameters(dict): updated into the "self" dict. """ dict.update(self, srcdict) + def _append_(self, *dicts): + """Appends dictionary search path to this Parameters object. + """ + self.__dict__["_list_"] += list(dicts) + def _prepend_(self, *dicts, **_options_): + """Prepends dictionary search path to this Parameters object. + This will not override the first dict, which is its own dictionary object. + If you really want to do that (BEWARE, know what you are doing!), + you will have to specify override_me=True in the argument. + """ + _list_ = self.__dict__["_list_"] + if not _options_.get("override_me", False): + self.__dict__["_list_"] = [ _list_[0] ] + list(dicts) + _list_[1:] + else: + self.__dict__["_list_"] = list(dicts) + _list_ def __add__(self, srcdict): """Returns a copy of the Parameters() object, with the most-overriding parameters updated from the contents of srcdict."""