Tab-Delimited CSV Import

Hey everyone:

I am currently working on a project that imports a .csv with basic data points into grasshopper. I understand the problem well enough, but I am having technical difficulties trying to get grasshopper to read TABS as TABS or even as "\t". Right now it appears as if the parser is simply removing these characters altogether. This makes it difficult to read the data, as you can imagine.

Am I right in assuming that grasshopper removing the Tab characters? Or are they just not being displayed within the panel? If it is removing the Tabs, does someone have a solution to avoid this? Any help would be appreciated.

I have tried using Lunchbox's Excel Reader component as well as the generic Read File component that comes standard with GH. Thanks!

- William

  • up

    Jesse

    An easy way to read certain sheets might be to use the ghowl plugin. It will let you pick which sheet to use when you import it.

    • up

      Stephen Maher

      Hi William,

      When you say "tabs" do you mean sheets? CSV files do not support sheets. A CSV creates one data set with each item separated by a comma. I'd try saving your file as an XLSX or some other extension that supports multiple sheets.

      Hope this helps. Let me know if I misunderstood something.

      Cheers,

      /SPM

      8
    • up

      William Carroll

      Here's the code I ended up with, and it works just fine. Thanks for the help, everyone.

      ----------------------------------------------------------

      # open file

      f = open(filename, 'r')

      # create list to store converted lines
      converted = []

      # read each line of f
      for line in f.readlines():
          # convert each line and add it to converted
          converted.append(line.replace('\t',','))

      # close file
      f.close()

      ----------------------------------------------------------

      I noticed when creating a blank list (i.e. "converted = []"), I could not construct one using the list() function. Is this something that's different between regular Python and IronPython? Which version of IronPython does the ghPython component support? I am trying to link the proper documentation to the text editor with which I am going to code. Does anyone have any suggestions?

      4