-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper fn to get bool from bool, int or str
The config file will supply all as str, so such a function will be useful For example, this commit also modifies the Sonde class to import helper and use this new function to check for the value of the skip argument by first converting the config provided value to bool.
- Loading branch information
1 parent
8a2e7e0
commit c933a45
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def get_bool(s): | ||
if isinstance(s, bool): | ||
return s | ||
elif isinstance(s, int): | ||
return bool(s) | ||
elif isinstance(s, str): | ||
lower_s = s.lower() | ||
if lower_s == "true": | ||
return True | ||
elif lower_s == "false": | ||
return False | ||
elif lower_s in ["0", "1"]: | ||
return bool(int(lower_s)) | ||
else: | ||
raise ValueError(f"Cannot convert {s} to boolean") | ||
else: | ||
raise ValueError(f"Cannot convert {s} to boolean") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters