espnet2.utils.types.str2bool
Less than 1 minute
espnet2.utils.types.str2bool
espnet2.utils.types.str2bool(value: str) → bool
Converts a string representation of truth values to a boolean.
This function utilizes the strtobool function from the distutils.util module to convert string values like ‘y’, ‘n’, ‘true’, ‘false’, ‘1’, ‘0’, etc., into their respective boolean representations.
- Parameters:value (str) – The string value to be converted to boolean. It should be one of the common truthy or falsy string representations.
- Returns: The boolean value corresponding to the input string.
- Return type: bool
Examples
>>> str2bool('true')
True
>>> str2bool('false')
False
>>> str2bool('1')
True
>>> str2bool('0')
False
>>> str2bool('yes')
True
>>> str2bool('no')
False
- Raises:ValueError – If the input string cannot be interpreted as a boolean.