-
Notifications
You must be signed in to change notification settings - Fork 63
Closed
Description
Environment
- netutils version:
Proposed Functionality
Would look to reimplement the distutils strtobool function.
Use Case
The taking a string and getting a boolean from it is helpful. Could be used in YAML manipulation (yes/no), or for reading from environment settings.
The distutils library that has the implementation is being retired and has deprecation warnings in it as of Python3.10. It would be nice to have a place to be able to get the same functionality from a trusted utility source. Understand if this is something that should not be here. Their advice is for each individual to implement their own.
Seeing this as an example:
_MAP = {
"y": True,
"yes": True,
"t": True,
"true": True,
"on": True,
"1": True,
"n": False,
"no": False,
"f": False,
"false": False,
"off": False,
"0": False,
}
def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError:
raise ValueError('"{}" is not a valid bool value'.format(value))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels