Skip to content

Instantly share code, notes, and snippets.

@DeybisMelendez
Created September 13, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeybisMelendez/42686b5d63aee8040f49e71af6798825 to your computer and use it in GitHub Desktop.
Save DeybisMelendez/42686b5d63aee8040f49e71af6798825 to your computer and use it in GitHub Desktop.
Leer archivos CSV con Godot
# Made by Deybis Melendez
extends Node
func simple_csv2Array(csv):
var file = File.new()
file.open(csv, File.READ)
var content = file.get_as_text()
content = content.split(",")
content = Array(content)
content.erase("") # debido a que generalmente dejamos una última coma
return content
func csv2Array(csv):
var file = File.new()
file.open(csv, File.READ)
var content = file.get_as_text()
content = content.split("\n")
content = Array(content)
content.erase("") #cleaning
var array = []
for item in content:
item = item.split(",")
item = Array(item)
item.erase("") #cleaning
array.append(item)
return array
func csv2Dict(csv):
var file = File.new()
file.open(csv, File.READ)
var content = file.get_as_text()
content = content.split("\n")
content = Array(content)
content.erase("") #cleaning
var dict = {}
for item in content:
var items = item.split(",")
items = Array(items)
items.erase("")
dict[items[0]] = items.duplicate()
dict[items[0]].erase(items[0])
return dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment