From 20861331098a30040c95d7a984394f5a9f1ca7e1 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Fri, 3 May 2024 11:40:53 +0200 Subject: [PATCH] Fix bool casting. A true value is any text that starts with `t` (case insensitive) or any non-zero integer. --- bin/fwr.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/fwr.py b/bin/fwr.py index e4362c0..57bbb5e 100644 --- a/bin/fwr.py +++ b/bin/fwr.py @@ -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):