Exporting to Excel through GhPython help!


I have been trying to export my text into a .csv format. The script works in exporting it, but always ends up with and indention in each one of the values as shown in the screenshot.

Attached is the file and screenshot
GhPython Excel Help!.gh (12.5 KB)


This should fix it:

import csv
import os

fpath = os.path.join(Directory, Filename)

with open(fpath, 'w') as f:
    for line in Lines:
        f.write(line + ",\n") 

Remove the \n if you want it all on a single line. It stands for new line.

GhPython Excel Help! 2.gh (5.0 KB)

Thank you very much! I was approaching it as separating it in gh then applying it to the python script.

Appreciate the help! :slight_smile:

Do you know why the extra space was being made in my script? I am still learning python and wanting to understand

If I had to guess, I’d say you probably accidentally introduced two \ns somewhere, which may not be visible in Grasshopper panels.