use try/except

This commit is contained in:
Raphael Deem 2017-06-26 21:26:34 -07:00
parent 4379a4b067
commit 395d85a12f

View File

@ -201,11 +201,10 @@ class Config(dict):
for k, v in os.environ.items(): for k, v in os.environ.items():
if k.startswith(SANIC_PREFIX): if k.startswith(SANIC_PREFIX):
_, config_key = k.split(SANIC_PREFIX, 1) _, config_key = k.split(SANIC_PREFIX, 1)
# This is a float or an int try:
if v.replace('.', '').isdigit(): self[config_key] = int(v)
if '.' in v: except ValueError:
try:
self[config_key] = float(v) self[config_key] = float(v)
else: except ValueError:
self[config_key] = int(v) self[config_key] = v
else:
self[config_key] = v