mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:17:08 +00:00
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:
10
bin/fwr.py
10
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):
|
||||
|
||||
Reference in New Issue
Block a user