Skip to main content

Table.write

writepathformaton_existing_filematch_columnson_problems

Group: Output

Documentation

This function writes a table from memory into a file. The specific behavior of the various File_Formats is specified below.

Arguments

  • path: The path to the output file.
  • format: The format of the file. If Auto_Detect is specified; the provided file determines the specific type and configures it appropriately. Details of this type are below.
  • on_existing_file: Specified how to handle if the file already exists.
  • match_columns: Specifies how to match columns against an existing file. If Match_Columns.By_Name - the columns are mapped by name against an existing file. If there is a mismatch, then a Column_Name_Mismatch error is raised. If Match_Columns.By_Position - the columns are mapped by position against an existing file. If there is a mismatch, then a Column_Count_Mismatch error is raised.
  • on_problems: Specifies how to handle if a problem occurs, raising as a warning by default. The specific issues depend on the File_Format argument.

Returns

  • If an unsupported File_Format is specified, an Illegal_Argument is raised. - If the path to the parent location cannot be found or the filename is invalid, a File_Error.Not_Found is raised. - If another IO error occurs, such as access denied, an File_Error.IO_Error is raised. - If appending and the columns do not match, a Column_Mismatch is raised. - Other specific errors or warnings that can be raised depend on the format argument. - On success, a File object for the written file is returned.

Examples

Write a table to a CSV file, without writing the header.

      import Standard.Examples

example_to_csv = Examples.inventory_table.write (Enso_Project.data / "example_csv_output.csv") (..Delimited delimiter="," headers=False)

Write a table to an XLSX file.

      import Standard.Examples
from Standard.Table import all

example_to_xlsx = Examples.inventory_table.write (enso_project.data / "example_xlsx_output.xlsx") (..Sheet "MySheetName")

Remarks

File_Format write behaviors

  • Auto_Detect: The file format is determined by the provided file.
  • Bytes and Plain_Text: The Table does not support these types in the write function. If passed as format, an Illegal_Argument is raised. To write out the table as plain text, the user needs to call the Text.from Table method and then use the Text.write function.