string.py
541 Bytes
def one_space(s):
s = s.strip()
while s.find(' ') > -1:
s = s.replace(' ', ' ')
return s
def to_str(v):
if isinstance(v, date):
return dmy(v)
if isinstance(v, datetime):
return dmyhms(v)
if v == 0:
return '0'
if isinstance(v, str):
return v.strip()
if isinstance(v, bool):
return v and '1' or '0'
return v and str(v) or ''
def dict_to_str(d):
r = {}
for key in d:
val = d[key]
r[key] = to_str(val)
return r