Export list to new line in csv

I want to export a list to csv but i want it to be a new line in the file.
It works if I send a single string but list cause an error.

I’m not great with python so I have hacked together a few scripts I found.

> 
import clr
import os
import datetime

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 

clr.AddReference('DynamoRevitDS')
import Dynamo

# Current doc and title
doc = DocumentManager.Instance.CurrentDBDocument
docTitle = doc.Title

# Check Dynamo workspace properties
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
script = currentWorkspace.Name

# Get properties for writing the log file
dateStamp   = datetime.datetime.today().strftime("%m/%d/%y")
userName    = os.environ.get('USERNAME')
userProfile = os.environ.get('USERPROFILE')

# Set Inputs
filepath = IN[0]
input = dateStamp + "," + docTitle + ".rvt" + "," + userName + "," +IN[1]

with open(filepath, 'a') as file:
		file.writelines(input + "\n")
result = True

OUT = "success"
1 Like

I would iterate the list first:

strings = ""
for i in IN[1]:
    strings += "," + i

input = dateStamp + "," + docTitle + ".rvt" + "," + userName + strings

Change the input to:
input = dateStamp + "," + docTitle + ".rvt" + "," + userName + "," + ",".join(IN[1])

1 Like

Thank you both for giving a quick response, I like the .join(IN[1]) solution better.

1 Like