iode.Lists.print_to_file

Lists.print_to_file(filepath: str | Path, names: str | List[str] = None, format: str = None)[source]

Print the list IODE lists defined by names to the file filepath using the format format.

Argument format must be in the list: - ‘H’ (HTML file) - ‘M’ (MIF file) - ‘R’ (RTF file) - ‘C’ (CSV file)

If argument format is null (default), the A2M format will be used to print the output.

If the filename does not contain an extension, it is automatically added based on the value of format.

If names is a string, it is considered as a pattern and the function will print all IODE lists matching the pattern. The following characters in pattern 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

If names is None, print all IODE lists of the (subset of the) current database.

Parameters:
filepath: str or Path

path to the file to print. If the filename does not contain an extension, it is automatically added based on the value of the format argument.

names: str or list of str, optional

pattern or list of names of the IODE lists to print. If None, print all IODE lists of the (subset of the) current database. Defaults to None.

format: str, optional

format of the output file. Possible values are: ‘H’ (HTML file), ‘M’ (MIF file), ‘R’ (RTF file) or ‘C’ (CSV file). Defaults to None meaning that the IODE lists will be dumped in the A2M format.

Examples

>>> from iode import lists, SAMPLE_DATA_DIR
>>> output_dir = getfixture('tmp_path')
>>> lists.load(f"{SAMPLE_DATA_DIR}/fun.lst")
Loading .../fun.lst
17 objects loaded
>>> lists.print_to_file(output_dir / "lists.csv", ["ENVI", "IDT", "MAINEQ"])
Printing IODE objects definition to file '...lists.csv'...
Printing ENVI ...
Printing IDT ...
Printing MAINEQ ...
Print done
>>> with open(output_dir / "lists.csv") as f:
...     print(f.read())
...
" - ENVI : EX;PWMAB;PWMS;PWXAB;PWXS;QWXAB;QWXS;POIL;NATY;TFPFHP_"
" - IDT : OCP;FLGR;KL;PROD;QL;RDEBT;RENT;RLBER;SBGX;WCRH;IUGR;SBGXR; WBGR;YSFICR;YSEFPR /* liste des identités */"
" - MAINEQ : W;NFYH;KNFF;PC;PXAB;PMAB;QXAB;QMAB;QC_"