I\'m reading a True - False value from a file and I need to convert it to boolean. Currently it always converts it to True even if the value is set
True - False
True
The cleanest solution that I've seen is:
from distutils.util import strtobool def string_to_bool(string): return bool(strtobool(str(string)))
Sure, it requires an import, but it has proper error handling and requires very little code to be written (and tested).