iode.Variables.merge
- Variables.merge(other: Self, overwrite: bool = True)
Merge the content of the ‘other’ database into the current database.
- Parameters:
- other:
other database to be merged in the current one.
- overwrite: bool, optional
Whether or not to overwrite the objects with the same name in the two database. Defaults to True.
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
>>> # copy comments with names starting with 'A' into a >>> # new database 'cmt_detached' >>> cmt_detached = comments.copy("A*") >>> cmt_detached.names ['ACAF', 'ACAG', 'AOUC', 'AQC']
>>> # remove 'ACAF' and 'ACAG' from the global Comments database >>> del comments['ACAF;ACAG'] >>> comments.get_names("A*") ['AOUC', 'AQC']
>>> # update the content of 'AOUC' in 'cmt_detached' >>> cmt_detached['AOUC'] = "Comment modified" >>> cmt_detached['AOUC'] 'Comment modified' >>> # content of 'AOUC' in the global Comments database >>> comments['AOUC'] 'Kost per eenheid produkt.'
>>> # merge 'cmt_detached' into the global Comments database >>> # -> preserve 'AOUC' in the global Comments database >>> comments.merge(cmt_detached, overwrite=False) >>> 'ACAF' in comments True >>> 'ACAG' in comments True >>> comments['AOUC'] 'Kost per eenheid produkt.'
>>> # merging 'cmt_detached' into the global Comments database >>> # -> overwrite the content of 'AOUC' in the global Comments database >>> comments.merge(cmt_detached) >>> comments['AOUC'] 'Comment modified'