Commit 4695d417 authored by sim's avatar sim

Add type conversion utilities

parent 047dc8de
def to_int(x, default=0):
try:
return int(x)
except (ValueError, TypeError):
return default
def to_bool(x):
return not (
x is None or isinstance(x, str) and (not x or x.lower() == 'false'))
def to_str(x):
if isinstance(x, str):
return x
return str(x)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment