Use int()
function with the argument s.strip() or 0
, i.e:
int(s.strip() or 0)
Or if you know that the string will always contain only digit characters or is empty (""
), then just:
int(s or 0)
In your specific case you can use lambda expression, e.g:
parse_table = [\
....
('numeric_field', lambda s: int(s.strip() or 0), 10), # int example
...
]