iode.Lists.__getitem__

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

Return the (subset of) IODE list(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 IODE list(s) to get. The list of lists to get can be specified by a pattern or by a list of sub-patterns (e.g. “A*;*_”).

Returns:
Single IODE list or a subset of the database.

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import lists
>>> lists.load(f"{SAMPLE_DATA_DIR}/fun.lst")
Loading .../fun.lst
17 objects loaded 
>>> # a) get one list
>>> lists["ENVI"]
['EX', 'PWMAB', 'PWMS', 'PWXAB', 'PWXS', 'QWXAB', 'QWXS', 'POIL', 'NATY', 'TFPFHP_']
>>> # b) get a subset of the Lists database using a pattern
>>> lists_subset = lists["E*"]
>>> lists_subset.names
['ENDO', 'ENDO0', 'ENDO1', 'ENVI']
>>> # c) get a subset of the Lists database using a list of names
>>> lists_subset = lists[["COPY", "ENDO", "ENVI", "TOTAL"]]
>>> lists_subset.names
['COPY', 'ENDO', 'ENVI', 'TOTAL']