ccheng
(Ccheng)
September 22, 2021, 6:38pm
1
Hello,
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)
diff-arch
(diff-arch)
September 22, 2021, 7:02pm
2
Hi,
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)
ccheng
(Ccheng)
September 22, 2021, 7:13pm
3
Thank you very much! I was approaching it as separating it in gh then applying it to the python script.
Appreciate the help!
ccheng
(Ccheng)
September 22, 2021, 7:40pm
4
Do you know why the extra space was being made in my script? I am still learning python and wanting to understand
diff-arch
(diff-arch)
September 22, 2021, 7:59pm
5
If I had to guess, I’d say you probably accidentally introduced two \n
s somewhere, which may not be visible in Grasshopper panels.