Import data .csv via python

Hello,

I want to create my own .csv reader

path = IN[0]
z=[]



with open(path) as csv_file:
	csv_reader = csv_file.readlines()
	for row in csv_reader:
		z.append(row.strip())
			

OUT = z

i get my data but i can`t acces it. Why?

should i change .csv file format. f.e. i want access different sheetnames Data1/Data2/Data3/…

Try using a string node for the ; separator, instead of a code block.

Try this, works on my end. Edit: in fact I made a custom node for it in Crumple (on github, will be in a future version).

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr
import csv
import os

# Preparing input from dynamo to revit
csvPath = IN[0]

# Try to read the file
if os.path.isfile(csvPath):
	with open(csvPath,"r") as file:
		reader = csv.reader(file,delimiter = ",")
		csv_data = list(reader)
	result = "CSV contents read."
else:
	csv_data = []
	result = "CSV contents not able to be read."

# Preparing output to Dynamo
OUT = [csv_data,result]

Below is the exporter from Crumple as well if it helps anyone:

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr
import csv
import os

# Preparing input from dynamo to revit
filePath = IN[0]
data     = IN[1]
deLimit  = IN[2]
append   = IN[3]

# Determine writemode
if append:
	writeMode = "a"
	modeName  = "appended"
else:
	writeMode = "w"
	modeName  = "written"

# Prepare data rows
csvData = []

try:
	for row in data:
		dataRow = deLimit.join(row)
		csvData.append(dataRow)
	doProceed = True
except:
	doProceed = False

# Try to write the file
if os.path.isfile(filePath) and doProceed:
	try:
		with open(filePath, writeMode) as file:
			for row in csvData:
				file.writelines(row + "\n")
		result = "CSV data " + modeName + " to existing file."
	except:
		result = "CSV file could not be accessed."
elif doProceed:
	try:
		with open(filePath, "w") as file:
			for row in csvData:
				file.writelines(row + "\n")
		result = "CSV data written to new file."
	except:
		result = "New CSV file could not be created."
else:
	result = "Data not writeable as CSV. Check types/formatting"

# Preparing output to Dynamo
OUT = [csvData, result]
4 Likes