use try/except
This commit is contained in:
parent
4379a4b067
commit
395d85a12f
|
@ -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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user