I'm trying to remove null and empty keys from my python object by calling a method from a module.
from file2 import remove_nulls
# initialize object and set attributes
obj.remove_nulls()
In my remove_nulls()
method, if I print the resultant object, I can observe that null and empty keys are removed, but after returning from the function, the final object still has the null and empty keys.
def remove_null(feature):
return json.dumps(del_none(feature.__dict__.copy()))
def del_none(d):
for key, value in list(d.items()):
if value is None:
del d[key]
elif isinstance(value, dict):
del_none(value)
return d
Can someone help to fine where it went wrong?