This library provides a simple function to convert string representations to boolean values. It explicitly recognizes 'yes', 'true', 'y', 't', '1' as True, and 'no', 'false', 'n', 'f', '0' as False, with case-insensitivity. This version (1.1) was released in 2017 and is currently in maintenance mode with no active development.
pip install str2boolVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing the `str2bool` function and converting various string inputs. Unrecognized strings default to `False`.
Consider using `pip install str2bool3` and `from str2bool3 import StrUtils` (then `StrUtils.str2bool(...)`) for an actively maintained fork, or `pip install python-strtobool` and `from str_to_bool import str_to_bool` for an alternative.
Understand that `str2bool` is designed to interpret string content (e.g., 'True', 'False') while `bool()` interprets the truthiness of the string object itself (e.g., an empty string is `False`, any other string is `True`). Use `str2bool` when you need to parse a string's explicit boolean meaning.
For new projects, avoid `distutils.util.strtobool`. Implement a custom string-to-boolean parsing function, or use a dedicated library like `str2bool` or its modern alternatives.
If you are encountering this `ValueError`, you are likely using `str2bool3` (or another fork) and calling `StrUtils.str2bool_exc()`. If you expect non-boolean strings and want them to default to `False`, use `StrUtils.str2bool()` instead or handle the `ValueError` explicitly. If you intended to use the original `str2bool` (v1.1), ensure `pip install str2bool` was run and you are importing `from str2bool import str2bool`.
Ensure the correct package is installed by running `pip install str2bool`. If you intended to use `str2bool3`, install it with `pip install str2bool3` and adjust imports to `from str2bool3 import StrUtils`. If using `python-strtobool`, install `pip install python-strtobool` and import `from str_to_bool import str_to_bool`.
No dependency data recorded yet.