From c4f0586a220e7b9da301cd7fd7a1024c53a52ec3 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 19 May 2010 03:41:37 -0400 Subject: [PATCH] Added input key flexibility to hooke.util.peak._kwarg --- hooke/util/peak.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hooke/util/peak.py b/hooke/util/peak.py index a572eec..1c4e86d 100644 --- a/hooke/util/peak.py +++ b/hooke/util/peak.py @@ -451,7 +451,7 @@ Minimum number of "feature" points for peak acceptance. for easy use by plugins in :mod:`~hooke.plugin`. """ -def _kwargs(kwargs, arguments, translations={}): +def _kwargs(kwargs, arguments, translations={}, argument_input_keys=False): """Split off kwargs for the arguments listed in arguments. Also add the kwargs marked in `translations`. @@ -463,11 +463,27 @@ def _kwargs(kwargs, arguments, translations={}): >>> kwargs = {'param_a':1, 'param_b':2, 'param_c':3} >>> args = [Argument(name='param a')] >>> translations = {'the_big_c_param':'param_c'} - >>> pprint.pprint(_kwargs(kwargs, args, translations)) + >>> pprint.pprint(_kwargs(kwargs, args, translations, + ... argument_input_keys=False)) + {'param_a': 1, 'the_big_c_param': 3} + >>> pprint.pprint(_kwargs(kwargs, args, translations, + ... argument_input_keys=True)) + {'the_big_c_param': 3} + >>> kwargs = {'param a':1, 'param b':2, 'param c':3} + >>> translations = {'the_big_c_param':'param c'} + >>> pprint.pprint(_kwargs(kwargs, args, translations, + ... argument_input_keys=True)) {'param_a': 1, 'the_big_c_param': 3} """ + arg_keys = [arg.name for arg in arguments] keys = [arg.name.replace(' ', '_') for arg in arguments] - ret = dict([(key, kwargs[key]) for key in keys]) + ret = {} + for arg_key,key in zip(arg_keys, keys): + in_key = key + if argument_input_keys == True: + in_key = arg_key + if in_key in kwargs: + ret[key] = kwargs[in_key] for target_key,source_key in translations.items(): if source_key in kwargs: ret[target_key] = kwargs[source_key] -- 2.26.2