iode.Database.copy
Note
Below, Database represents either:
Comments
Equations
Identities
Lists
Scalars
Tables
Variables
- Database.copy(self) Self
Create a copy of an IODE database. Any change made on the copied database will NOT modify the corresponding the global IODE database.
- Returns:
- Database
Examples
>>> from iode import SAMPLE_DATA_DIR >>> from iode import comments >>> comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
Database subset
>>> # without using copy(), any modification made on >>> # the copy subset will also change the corresponding >>> # IODE database >>> cmt_subset = comments["A*"] >>> cmt_subset.names ['ACAF', 'ACAG', 'AOUC', 'AQC'] >>> # a) add a comment >>> cmt_subset["A_NEW"] = "New comment" >>> "A_NEW" in cmt_subset True >>> "A_NEW" in comments True >>> comments["A_NEW"] 'New comment' >>> # b) modify a comment >>> cmt_subset["ACAF"] = "Modified Comment" >>> cmt_subset["ACAF"] 'Modified Comment' >>> comments["ACAF"] 'Modified Comment' >>> # c) delete a comment >>> del cmt_subset["ACAG"] >>> "ACAG" in cmt_subset False >>> "ACAG" in comments False
Copied database subset
>>> cmt_subset_copy = comments["B*"].copy() >>> cmt_subset_copy.names ['BENEF', 'BENEF_', 'BQY', 'BVY'] >>> # by using copy(), any modification made on the copy subset >>> # let the global workspace unchanged >>> # a) add a comment -> only added in the copied subset >>> cmt_subset_copy["B_NEW"] = "New Comment" >>> "B_NEW" in cmt_subset_copy True >>> "B_NEW" in comments False >>> # b) modify a comment -> only modified in the copied subset >>> cmt_subset_copy["BENEF"] = "Modified Comment" >>> cmt_subset_copy["BENEF"] 'Modified Comment' >>> comments["BENEF"] 'Ondernemingen: niet-uitgekeerde winsten.' >>> # c) delete a comment -> only deleted in the copied subset >>> del cmt_subset_copy["BENEF_"] >>> "BENEF_" in cmt_subset_copy False >>> "BENEF_" in comments True