optdict2str
- opthandler.optdict2str(optdict, skiped_opts=None, dumped_vals=None)[source]
Convert an option dictionary to an option string.
- Parameters:
optdict (
dict
) – The option dictionary that should be converted to an option list.skiped_opts (
list
ortuple
orNone
, optional) – If notNone
, skip key-value pairs of the input dictionary whose value is contained in skiped_opts.dumped_vals (
list
ortuple
orNone
, optional) – If notNone
, don’t include the given values of the input dictionary in the returned option list.
- Returns:
optstr (
str
) – The resulting option string. Each key of optdict is prefixed with either a single hyphen ('-'
) or two hyphens, depending on whether the key consists of a single character or multiple characters.
See also
optdict2list()
Convert an option dictionary to an option list
shlex.join()
Convert an option list to an option string
Notes
This function simply applies
shlex.join()
on the output ofoptdict2list()
.Examples
>>> optdict2str({'a': 0, 'Bc': 'xY'}) '-a 0 --Bc xY' >>> optdict2str({' a': 0, ' Bc ': 'xY '}) '-a 0 --Bc xY' >>> optdict2str({'a': 0, 'Bc': 'xY Ab'}) "-a 0 --Bc 'xY Ab'" >>> optdict2str({'a': 0, 'Bc': '', 'xy': 'z'}) '-a 0 --Bc --xy z' >>> optdict2str( ... {'a': 0, 'Bc': None, 'xy': False}, ... skiped_opts=('None', 'False'), ... ) '-a 0' >>> optdict2str( ... {'a': 0, 'Bc': None, 'xy': False}, ... skiped_opts=(None, False), ... ) '-a 0 --Bc None --xy False' >>> optdict2str( ... {'a': 0, 'Bc': None, 'xy': True}, ... dumped_vals=('None', 'True'), ... ) '-a 0 --Bc --xy'