iode.ComputedTable.print_to_file

ComputedTable.print_to_file(destination_file: str | Path, format: str = None)[source]

Print the present computed table to a file.

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

If argument format is None (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 format.

Parameters:
destination_file: str or Path

The destination file for printing

format: str, optional

The format of the output file. Deduced from the extension if not provided. If destination_file has no extension and format is None, the A2M format is used.

Examples

>>> from pathlib import Path
>>> from iode import SAMPLE_DATA_DIR
>>> from iode import Table, tables, variables
>>> output_dir = getfixture('tmp_path')
>>> tables.load(f"{SAMPLE_DATA_DIR}/fun.tbl")
Loading .../fun.tbl
46 objects loaded 
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> computed_table = tables["C8_1"].compute("(2010;2010/2009):5")
>>> computed_table
   line title \ period[file]     |    10    | 10/09 |    11    | 11/10 | ... |    14    | 14/13
-------------------------------------------------------------------------...--------------------
Output potentiel                 |  6936.11 |  1.74 |  7045.34 |  1.57 | ... |  7460.12 |  2.16
Stock de capital                 | 11293.85 |  2.82 | 11525.01 |  2.05 | ... | 12263.95 |  2.41
Intensité de capital             |     0.39 | -2.17 |     0.38 | -2.05 | ... |     0.36 | -1.90
Productivité totale des facteurs |     1.10 |  1.00 |     1.11 |  1.00 | ... |     1.14 |  1.00

>>> computed_table.print_to_file(output_dir / "computed_table_2_periods.csv")
>>> with open(output_dir / "computed_table_2_periods.csv", "r") as f:
...     print(f.read())
"Déterminants de l'output potentiel"

" ","10","10/09","11","11/10","12","12/11","13","13/12","14","14/13",

"Output potentiel","6936.11","1.74",...,"7460.12","2.16",       
"Stock de capital","11293.85","2.82",...,"12263.95","2.41",  
"Intensité de capital","0.39","-2.17",...,"0.36","-1.90",
"Productivité totale des facteurs","1.10","1.00",...,"1.14","1.00",      
>>> extra_files = Path(SAMPLE_DATA_DIR) / "ref.av"
>>> computed_table = tables["C8_1"].compute("2010[1-2]:5", extra_files=extra_files)
>>> computed_table
   line title \ period[file]     | 10[1-2] | 11[1-2] | 12[1-2] | 13[1-2] | 14[1-2]
-----------------------------------------------------------------------------------
Output potentiel                 |  138.72 |  140.91 |  143.23 |  146.05 |  149.20
Stock de capital                 |  225.88 |  230.50 |  234.74 |  239.51 |  245.28
Intensité de capital             |    0.01 |    0.01 |    0.01 |    0.01 |    0.01
Productivité totale des facteurs |    0.02 |    0.02 |    0.02 |    0.02 |    0.02

>>> computed_table.print_to_file(output_dir / "computed_table_2_files.csv")    
>>> with open(output_dir / "computed_table_2_files.csv", "r") as f:
...     print(f.read())
"Déterminants de l'output potentiel"

" ","10[1-2]","11[1-2]","12[1-2]","13[1-2]","14[1-2]",

"Output potentiel","138.72","140.91","143.23","146.05","149.20",
"Stock de capital","225.88","230.50","234.74","239.51","245.28",
"Intensité de capital","0.01","0.01","0.01","0.01","0.01",
"Productivité totale des facteurs","0.02","0.02","0.02","0.02","0.02",