Closed shahid1579 closed 4 years ago
def get_nested_value(d, key):
"""Return a dictionary item given a dictionary d
and a flattened key from get_column_names
.
Example:
d = {
'a': {
'b': 2,
'c': 3,
},
}
key = 'a.b'
will return: 2
"""
print (key)
print(d)
if '.' not in key:
if key not in d:
return None
return d[key]
base_key, sub_key = key.split('.', 1)
if base_key not in d:
return None
sub_dict = d[base_key]
**if sub_dict is None:
return None**
return get_nested_value(sub_dict, sub_key)
Because some json data don't have nested value. the value is null,so the recursion can get NoneType. add one line check "sub_dict is None: return None" to break the recursion. After that, It will be working fine.
@ Thanks @fuyi1215 you Solved my Problem.
business.json is not converted to business.csv TypeError: argument of type 'NoneType' is not iterable