iode.Tables.print_to_file

Tables.print_to_file(filepath: str | Path, names: str | List[str] = None, format: str = None, generalized_sample: str = None, nb_decimals: int = 4)[source]

Print the list tables 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 tables 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 tables 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 tables to print. If None, print all tables 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 tables will be dumped in the A2M format.

generalized_sample: str

generalized sample to use for computing the tables. Mandatory if print_tables_as is PrintTablesAs.COMPUTED.

nb_decimals: int, optional

number of decimals to use for computing the tables. Only used if print_tables_as is PrintTablesAs.COMPUTED. Defaults to 4.

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import tables, scalars, variables, PrintTablesAs, load_extra_files
>>> output_dir = getfixture('tmp_path')
>>> scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl")
Loading .../fun.scl
161 objects loaded
>>> 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
>>> tables["ANAKNFF"]
DIVIS |                                  1 |
TITLE |                "Déterminants de la croissance de K"
----- | ------------------------------------------------------------------
CELL  |                                    |              "#s"
----- | ------------------------------------------------------------------
CELL  | "Croissance de K "                 |                      dln KNFF
CELL  | "Output gap "                      |    knff1*ln (QAFF_/(Q_F+Q_I))
CELL  | "Rentabilité "                     |          knf2*ln mavg(3,RENT)
CELL  | "Croissance anticipée de l'output" | 0.416*mavg(4,dln QAFF_)+0.023

nb lines: 8
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables["ANAPRIX"]
DIVIS | 1                            |
TITLE |                        "Analyse des prix"
----- | ---------------------------------------------------------------
CELL  |                              |               "#s"
----- | ---------------------------------------------------------------
CELL  | "GAP_"                       |                             GAP_
CELL  | "dln (PC/(1+ITCR))-dln AOUC" | 100*(dln (PC/(1+ITCR))-dln AOUC)

nb lines: 6
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables.print_tables_as = PrintTablesAs.TITLES
>>> tables.print_to_file(output_dir / "tables_titles.csv", ["ANAKNFF", "ANAPRIX"])
Printing IODE objects definition to file '...tables_titles.csv'...
Printing ANAKNFF ...
Printing ANAPRIX ...
Print done
>>> with open(output_dir / "tables_titles.csv") as f:
...     print(f.read())
...
"ANAKNFF : Déterminants de la croissance de K"
"ANAPRIX : Analyse des prix"
>>> tables.print_tables_as = PrintTablesAs.FULL
>>> tables.print_to_file(output_dir / "tables_full.csv", ["ANAKNFF", "ANAPRIX"])
Printing IODE objects definition to file '...tables_full.csv'...
Printing ANAKNFF ...
Printing ANAPRIX ...
Print done
>>> with open(output_dir / "tables_full.csv") as f:
...     print(f.read())
...
"ANAKNFF : definition",

"""Déterminants de la croissance de K""",

" ","""#s""",

"""Croissance de K ""","dln KNFF",
"""Output gap ""","knff1*ln (QAFF_/(Q_F+Q_I))",
"""Rentabilité ""","knf2*ln mavg(3,RENT)",
"""Croissance anticipée de l'output""","0.416*mavg(4,dln QAFF_)+0.023",

"ANAPRIX : definition",

"""Analyse des prix""",

" ","""#s""",

"""GAP_""","GAP_",
"""dln (PC/(1+ITCR))-dln AOUC""","100*(dln (PC/(1+ITCR))-dln AOUC)",

>>> tables["C8_1"]
DIVIS | 1                                  |
TITLE |      "Déterminants de l'output potentiel"
----- | ---------------------------------------------
CELL  |                                    |   "#s"
----- | ---------------------------------------------
CELL  | "Output potentiel"                 |  Q_F+Q_I
CELL  | "Stock de capital"                 | KNFF[-1]
CELL  | "Intensité de capital"             |    KLFHP
CELL  | "Productivité totale des facteurs" |  TFPFHP_

nb lines: 8
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables["C8_2"]
DIVIS | 1                      |
TITLE |     "Déterminants de la productivité"
----- | ------------------------------------------
CELL  |                        |        "#s"
----- | ------------------------------------------
CELL  | "Productivité"         | (QAFF_/(NFY+NIY))
CELL  | "Intensité de capital" |    KLFHP**(-0.31)
CELL  | "TFPFHP_"              |           TFPFHP_

nb lines: 7
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables["C8_3"]
DIVIS | 1                                |
TITLE |               "Output gap"
----- | ---------------------------------------
CELL  |                                  | "#s"
----- | ---------------------------------------
CELL  | "Output gap (methodologie FPB)." | GAP_

nb lines: 5
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables["C8_4"]
DIVIS | 1                              |
TITLE |  "Déterminants de la croissance du stock de capital"
----- | -----------------------------------------------------
CELL  |                                |         "#s"
----- | -----------------------------------------------------
CELL  | "Croissnce du stoc de capital" |             dln KNFF
CELL  | "Rentabilité"                  | 0.04*ln mavg(3,RENT)

nb lines: 6
nb columns: 2
language: 'ENGLISH'
gridx: 'MAJOR'
gridy: 'MAJOR'
graph_axis: 'VALUES'
graph_alignment: 'LEFT'
>>> tables.print_tables_as = PrintTablesAs.COMPUTED
>>> names = ["C8_1", "C8_2", "C8_3", "C8_4"]
>>> tables.print_to_file(output_dir / "tables_2_periods.csv", names, 
...                      generalized_sample="(2010;2010/2009):5", nb_decimals=4)
>>> with open(output_dir / "tables_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.1120","1.7386","7045.3431","1.5748","7161.5414","1.6493","7302.2903","1.9653","7460.1153","2.1613",
"Stock de capital","11293.8486","2.8185","11525.0126","2.0468","11736.7826","1.8375","11975.4885","2.0338","12263.9472","2.4087",
"Intensité de capital","0.3855","-2.1730","0.3776","-2.0452","0.3704","-1.9140","0.3635","-1.8641","0.3566","-1.8968",
"Productivité totale des facteurs","1.0977","1.0000","1.1087","1.0000","1.1198","1.0000","1.1310","1.0000","1.1423","1.0000",
"Déterminants de la productivité"

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

"Productivité","2.1305","1.4222","2.1746","2.0711","2.2181","2.0014","2.2593","1.8562","2.2957","1.6105",
"Intensité de capital","1.3438","0.6834","1.3524","0.6426","1.3606","0.6009","1.3685","0.5850","1.3767","0.5954",
"TFPFHP_","1.0977","1.0000","1.1087","1.0000","1.1198","1.0000","1.1310","1.0000","1.1423","1.0000",
"Output gap"

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

"Output gap (methodologie FPB).","3.3765","-11.6805","3.5664","5.6238","3.7392","4.8438","3.6566","-2.2090","3.3138","-9.3736",
"Déterminants de la croissance du stock de capital"

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

"Croissnce du stoc de capital","0.0203","-27.1039","0.0182","-10.1346","0.0201","10.5786","0.0238","18.2162","0.0244","2.4760",
"Rentabilité","-0.0093","34.5565","-0.0100","7.5121","-0.0100","0.3108","-0.0100","0.1740","-0.0103","2.4613",
>>> extra_files = load_extra_files(f"{SAMPLE_DATA_DIR}/ref.av")
Loading ...ref.av
...
394 objects loaded
>>> extra_files[0].name
'ref.av'
>>> tables.print_to_file(output_dir / "tables_2_files.csv", names, generalized_sample="2010[1-2]:5", nb_decimals=4)    
>>> with open(output_dir / "tables_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.7221","140.9067","143.2307","146.0457","149.2022",
"Stock de capital","225.8768","230.5000","234.7354","239.5095","245.2787",
"Intensité de capital","0.0077","0.0076","0.0074","0.0073","0.0071",
"Productivité totale des facteurs","0.0220","0.0222","0.0224","0.0226","0.0228",
"Déterminants de la productivité"

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

"Productivité","0.0000","-0.0000","-0.0000","0.0000","0.0000",
"Intensité de capital","-0.0084","-0.0085","-0.0085","-0.0086","-0.0086",
"TFPFHP_","0.0220","0.0222","0.0224","0.0226","0.0228",
"Output gap"

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

"Output gap (methodologie FPB).","-0.0000","0.0000","0.0000","0.0000","0.0000",
"Déterminants de la croissance du stock de capital"

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

"Croissnce du stoc de capital","0.0000","-0.0000","-0.0000","0.0000","-0.0000",
"Rentabilité","0.0000","-0.0000","-0.0000","-0.0000","0.0000",