Convert a string to a boolean. Supported true values: 'yes', 'true', 't', 'y', '1' Supported false values: 'no', 'false', 'f', 'n', '0' Args: v (str): String to convert. Returns: bool: Converted boolean value. Raises: argparse.ArgumentTypeError: I
(v)
| 29 | |
| 30 | |
| 31 | def str2bool(v): |
| 32 | """ |
| 33 | Convert a string to a boolean. |
| 34 | |
| 35 | Supported true values: 'yes', 'true', 't', 'y', '1' |
| 36 | Supported false values: 'no', 'false', 'f', 'n', '0' |
| 37 | |
| 38 | Args: |
| 39 | v (str): String to convert. |
| 40 | |
| 41 | Returns: |
| 42 | bool: Converted boolean value. |
| 43 | |
| 44 | Raises: |
| 45 | argparse.ArgumentTypeError: If the value cannot be converted to boolean. |
| 46 | """ |
| 47 | if isinstance(v, bool): |
| 48 | return v |
| 49 | v_lower = v.lower() |
| 50 | if v_lower in ('yes', 'true', 't', 'y', '1'): |
| 51 | return True |
| 52 | elif v_lower in ('no', 'false', 'f', 'n', '0'): |
| 53 | return False |
| 54 | else: |
| 55 | raise argparse.ArgumentTypeError('Boolean value expected (True/False)') |
| 56 | |
| 57 | def cache_video(tensor, |
| 58 | save_file=None, |
nothing calls this directly
no outgoing calls
no test coverage detected