Name

loadTable()

Examples
# The following short CSV file called "mammals.csv" is parsed
# in the code below. It must be in the project's "data" folder.
#
# id,species,name
# 0,Capra hircus,Goat
# 1,Panthera pardus,Leopard
# 2,Equus zebra,Zebra
table = loadTable("mammals.csv", "header")
print("%i total rows in table" % (table.getRowCount()))
for row in table.rows():
  mammal_id = row.getInt("id")
  species = row.getString("species")
  name = row.getString("name")
  print(name + " (" + species + ") has an ID of " + str(mammal_id))

# Sketch prints:
# 3 total rows in table
# Goat (Capra hircus) has an ID of 0
# Leopard (Panthera pardus) has an ID of 1
# Zebra (Equus zebra) has an ID of 2
Description Reads the contents of a file or URL and creates an Table object with its values. If a file is specified, it must be located in the sketch's "data" folder. The filename parameter can also be a URL to a file found online. By default, the file is assumed to be comma-separated (in CSV format). To use tab-separated data, include "tsv" in the options parameter.

If the file contains a header row, include "header" in the options parameter. If the file does not have a header row, then simply omit the "header" option.

When specifying both a header and the file type, separate the options with commas, as in: loadTable("data.csv", "header, tsv")

All files loaded and saved by the Processing API use UTF-8 encoding.
Syntax
loadTable(filename)
loadTable(filename, options)
Parameters
filenameString: name of a file in the data folder or a URL.
Related Table
saveTable()
loadBytes()
loadStrings()
loadXML()

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.