forked from martiby/ess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
33 lines (28 loc) · 698 Bytes
/
Copy pathutils.py
File metadata and controls
33 lines (28 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def limit(value, min, max):
if value > max:
return max
elif value < min:
return min
else:
return value
def dictget(dic, key, default=None):
"""
Recursive get from dictionary.
:param dic: source dictionary
:param key: key or keylist
:return: value
"""
v = None
try:
if not isinstance(key, (tuple, list)): # normal get from dictionary
v = dic[key]
else:
v = dic
for k in key: # loop over keys
v = v[k]
except (KeyError, IndexError, TypeError):
v = None
if default is not None and v is None:
return default
else:
return v