iode.Comments.__getitem__

Comments.__getitem__(key: str | List[str]) str | Self[source]

Return the (subset of) comment(s) referenced by key.

The key can represent a single object name (e.g. “ACAF”) or a list of object names (“ACAF;ACAG;AOUC”) or a pattern (e.g. “A*”) or a list of sub-patterns (e.g. “A*;*_”).

If the key represents a list of object names or of sub-patterns, each name or sub-pattern is separated by a separator character which is either a whitespace ` , or a comma `,, or a semi-colon ;, or a tabulation t, or a newline n.

A (sub-)`pattern` is a list of characters representing a group of object names. It includes some special characters which have a special meaning:

  • * : any character sequence, even empty

  • ? : any character (one and only one)

  • @ : any alphanumerical char [A-Za-z0-9]

  • & : any non alphanumerical char

  • | : any alphanumeric character or none at the beginning and end of a string

  • ! : any non-alphanumeric character or none at the beginning and end of a string

  • `` : escape the next character

Note that the key can contain references to IODE lists which are prefixed with the symbol $.

Parameters:
key: str or list(str)

(the list of) name(s) of the comment(s) to get. The list of comments to get can be specified by a pattern or by a list of sub-patterns (e.g. “A*;*_”).

Returns:
Single comment or a subset of the database.

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) get one Comment
>>> comments["ACAF"]
'Ondernemingen: ontvangen kapitaaloverdrachten.'
>>> # b) get a subset of the Comments database using a pattern
>>> comments_subset = comments["A*"]
>>> comments_subset.names
['ACAF', 'ACAG', 'AOUC', 'AQC']
>>> # c) get a subset of the Comments database using a list of names
>>> comments_subset = comments[["ACAF", "AOUC", "BQY", "BVY"]]
>>> comments_subset.names
['ACAF', 'AOUC', 'BQY', 'BVY']