Skip to content
Snippets Groups Projects
Commit e9fcfe1f authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

[utils] add a function to get parameters from either configuration file or command-line

parent fe101e24
No related branches found
No related tags found
1 merge request!6Resolve "Package depends on both bob.db.cohface and bob.db.hci_tagging"
...@@ -99,3 +99,46 @@ def build_bandpass_filter(fs, order, plot=False): ...@@ -99,3 +99,46 @@ def build_bandpass_filter(fs, order, plot=False):
pyplot.show() pyplot.show()
return b return b
def get_parameter(args, configuration, keyword, default):
""" Get the right value for a parameter
The parameters are either defined in a separate configuration file
or given directly via command-line. Note that the command-line
has priority over the configuration file.
As a convention, parameters made with more than one word
are provided with an underscore in the configuration file, and with an
hyphen in the command-line:
- configuration: batch_size=64
- command line: --batch-size=64
Parameters
----------
args: dictionary
The arguments as parsed from the command line.
configuration: object
The arguments given by the configuration file.
keyword: string
the keyword for the parameter to process (in the "configuration" style)
default:
The default value of the parameter
Returns
-------
arg:
The right value for the given keyword argument
"""
args_kw = '--' + keyword.replace('_', '-')
_type = type(default)
arg = _type(args[args_kw])
if hasattr(configuration, keyword):
arg = getattr(configuration, keyword)
if _type(args[args_kw]) is not default:
arg = _type(args[args_kw])
return arg
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment