Fix bool casting.

A true value is any text that starts with `t` (case insensitive) or
any non-zero integer.
This commit is contained in:
D. Berge
2024-05-03 11:40:53 +02:00
parent bb70cf1a3d
commit 2086133109

View File

@@ -6,11 +6,19 @@ Fixed width record importing functions.
import builtins
def to_bool (v):
try:
return bool(int(v))
except ValueError:
if type(v) == str:
return v.strip().lower().startswith("t")
return False
transform = {
"int": lambda v: builtins.int(float(v)),
"float": float,
"string": str,
"bool": bool
"bool": to_bool
}
def parse_line (line, fields):