espnet2.utils.types.str2pair_str
Less than 1 minute
espnet2.utils.types.str2pair_str
espnet2.utils.types.str2pair_str(value: str) → Tuple[str, str]
Convert a string representation of a pair into a tuple of strings.
This function takes a string formatted as ‘string1,string2’ and converts it into a tuple containing the two strings. It also handles any surrounding parentheses or quotes that may be present in the input string.
- Parameters:value (str) – A string representing a pair, formatted as ‘string1,string2’.
- Returns: A tuple containing the two strings extracted from the : input.
- Return type: Tuple[str, str]
Examples
>>> import argparse
>>> str2pair_str('abc,def ')
('abc', 'def')
>>> parser = argparse.ArgumentParser()
>>> _ = parser.add_argument('--foo', type=str2pair_str)
>>> parser.parse_args(['--foo', 'abc,def'])
Namespace(foo=('abc', 'def'))
NOTE
This function also trims any whitespace around the input strings and removes any enclosing parentheses or quotes.
- Raises:ValueError – If the input string does not contain exactly one comma, resulting in an inability to split the string into two parts.