CSV

Inherits: Resource < RefCounted < Object

Resource containing delimiter-separated values parsed as dictionaries.

Description

CSV stores rows parsed from CSV, TSV, PSV, or other delimiter-separated text. When headers is enabled, the first row is used as dictionary keys. Otherwise rows are stored with numeric column indexes.

Tutorials

Properties

PackedStringArray

comment_prefixes

PackedStringArray()

String

delimiter

","

PackedStringArray

false_values

PackedStringArray("false", "False", "FALSE")

bool

headers

false

PackedStringArray

null_values

PackedStringArray("")

int

row_length_mode

0

Array[Dictionary]

rows

[]

bool

skip_empty_rows

false

bool

trim_fields

false

PackedStringArray

true_values

PackedStringArray("true", "True", "TRUE")

Methods

Variant

convert_to_variant(text: String) const

Dictionary

get_parser_options() const

Error

load_file(path: String)

Error

load_string(string: String)

String

save_to_string() const


Enumerations

enum RowLengthMode: 🔗

RowLengthMode ROW_LENGTH_STRICT = 0

Rejects input when any accepted row has a different field count than the first accepted row.

RowLengthMode ROW_LENGTH_PAD_SHORT = 1

Pads short rows with empty fields and rejects rows that have too many fields.

RowLengthMode ROW_LENGTH_PAD_OR_TRUNCATE = 2

Pads short rows with empty fields and truncates rows that have too many fields.

RowLengthMode ROW_LENGTH_JAGGED = 3

Allows rows to keep their original field counts.


Property Descriptions

PackedStringArray comment_prefixes = PackedStringArray() 🔗

Lines whose first parsed field begins with any of these prefixes are skipped while loading.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


String delimiter = "," 🔗

The one-character delimiter used while loading and saving.


PackedStringArray false_values = PackedStringArray("false", "False", "FALSE") 🔗

Field values that convert_to_variant() and CSV importer methods convert to false.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


bool headers = false 🔗

  • void set_headers(value: bool)

  • bool get_headers()

If true, the first parsed row is used as dictionary keys.


PackedStringArray null_values = PackedStringArray("") 🔗

Field values that convert_to_variant() and CSV importer methods convert to null.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


int row_length_mode = 0 🔗

  • void set_row_length_mode(value: int)

  • int get_row_length_mode()

Controls how rows with fewer or more fields than the first accepted row are handled. See RowLengthMode.


Array[Dictionary] rows = [] 🔗

Parsed row dictionaries.


bool skip_empty_rows = false 🔗

  • void set_skip_empty_rows(value: bool)

  • bool get_skip_empty_rows()

If true, rows containing only empty fields are skipped while loading.


bool trim_fields = false 🔗

  • void set_trim_fields(value: bool)

  • bool get_trim_fields()

If true, leading and trailing whitespace is removed from unquoted fields while loading.


PackedStringArray true_values = PackedStringArray("true", "True", "TRUE") 🔗

Field values that convert_to_variant() and CSV importer methods convert to true.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.


Method Descriptions

Variant convert_to_variant(text: String) const 🔗

Converts a field string to a Variant using the same conversion rules as CSVImporter.parse_record().


Dictionary get_parser_options() const 🔗

Returns the parser options generated from this resource's parser properties. The dictionary can be passed to DSVImporter.import_string(), CSVImporter.import_string(), or CSVImporter.parse_record().


Error load_file(path: String) 🔗

Loads delimiter-separated data from path into rows.


Error load_string(string: String) 🔗

Loads delimiter-separated data from string into rows.


String save_to_string() const 🔗

Serializes rows as delimiter-separated text.