Import CSV/TSV files as native Array or Dictionaries.
To install, download the ZIP archive, extract it, and move the addons/ folder it
contains into your project folder. Then, enable the plugin in project settings.
To use this importer, select the CSV/TSV file, change Import As to "CSV Data" in the Import dock, set the import options and click Reimport.
The CSV/TSV file will be imported as a custom Resource object. Lines in the
file will be turned into elements of an array named records on the object.
func _ready():
var data = preload("res://example.csv")
print(data.records) # array of dataThe type of array elements is determined by the import options. records is
an array of string arrays by default.
- Delimiter
- Use "Comma" for CSV and "Tab" for TSV.
- Headers
- Use the first line as header fields.
Each element of
recordswill be aDictionarywith header fields as keys.
- Use the first line as header fields.
Each element of
- Detect Numbers
- Convert fields from string to
intorfloatwhen possible.
- Convert fields from string to
- Force Float
- Always use
floatwhen detecting numbers.
- Always use
After importing res://example.csv:
Apple,Banana,Cherry,Durian
-12,13,14.0,20.5The value of preload("res://example.csv").records will be:
# By default
[
["Apple", "Banana", "Cherry", "Durian"],
["-12", "13", "14.0", "20.5"],
]
# With "Headers" enabled
[
{
"Apple": "-12",
"Banana": "13",
"Cherry": "14.0",
"Durian": "20.5",
},
]
# With "Detect Numbers" and "Force Float" enabled
[
["Apple", "Banana", "Cherry", "Durian"],
[-12.0, 13.0, 14.0, 20.5],
# With "Detect Numbers" enabled and "Force Float" disabled
[
["Apple", "Banana", "Cherry", "Durian"],
[
-12, # int
13, # int
14.0, # float
20.5, # float
],
]