iode.Comments.__delitem__

Comments.__delitem__(key)[source]

Remove the (subset of) comment(s) referenced by key from the Comments database.

Parameters:
key: str or list(str)

(list of) name(s) of the comment(s) to be removed. The list of names can be given as a string pattern (e.g. “A*;*_”).

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import comments
>>> comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
Loading .../fun.cmt
317 objects loaded 
>>> # a) delete one comment
>>> comments.get_names("A*")
['ACAF', 'ACAG', 'AOUC', 'AQC']
>>> del comments["ACAF"]
>>> comments.get_names("A*")
['ACAG', 'AOUC', 'AQC']
>>> # b) delete several comments at once using a pattern
>>> del comments["A*"]
>>> comments.get_names("A*")
[]
>>> # c) delete several comments at once using a list of names
>>> comments.get_names("B*")
['BENEF', 'BENEF_', 'BQY', 'BVY']
>>> del comments[["BENEF", "BQY"]]
>>> comments.get_names("B*")
['BENEF_', 'BVY']
>>> # delete one comment from a subset of the global database
>>> comments_subset = comments["D*"]
>>> comments_subset.names
['DPU', 'DPUF', 'DPUG', 'DPUGO', 'DPUH', 'DPUU', 'DTF', 'DTFX', 'DTH', 'DTH1', 'DTH1C', 'DTHX']
>>> del comments_subset["DPUGO"]
>>> comments_subset.names
['DPU', 'DPUF', 'DPUG', 'DPUH', 'DPUU', 'DTF', 'DTFX', 'DTH', 'DTH1', 'DTH1C', 'DTHX']
>>> # NOTE: the comment has also been deleted from the global database
>>> "DPUGO" in comments
False
>>> comments.get_names("D*")
['DPU', 'DPUF', 'DPUG', 'DPUH', 'DPUU', 'DTF', 'DTFX', 'DTH', 'DTH1', 'DTH1C', 'DTHX']