Remove an object from a dataset collection.
We need our usual pre-amble before using dataset.
from py_dataset import dataset
Assuming that was done then our Python code is pretty simple to remove an object from a collection.
= 'things.ds'
c_name = 'thing-one'
key if not dataset.delete(c_name, key):
= dataset.error_message()
err print(f'failed to delete {key} from {c_name}, {err}')
Note that ‘thing-one’ must exist in the collection ‘things.ds’. If
not the delete()
method returns False and you should hanlde
the error.
We can confirm the deletion with has_key()
if not dataset.has_key(c_name, key):
print('somthing went wrong')