Grasshopper

algorithmic modeling for Rhino

Hey all,

I thought this a simple problem with a simple solution, but I haven't had any success thus far.

I'm using the [Read Me] component to read a CSV file, which contains a series of decimal numbers. I'm struggling with converting the CSV data (read as strings) to floats. I've tried using [float(i) for i in x], but this calls the tree branch (i.e. {0;0;0}, etc.) as opposed to the string item. Image attached.

Anyone have the know-how?

Thanks,

/SPM

Views: 9714

Attachments:

Replies are closed for this discussion.

Replies to This Discussion

Where ever grasshopper requires numbers instead if text it will convert them. But you can force the issue by using a Number Param component before going into you python component. Or do you what to do this purely in python

Just an addition to Danny's great answer:

When dealing with python list comprehensions, you do not have to define an empty list first. Just write:

a = [float(i) for i in x]

Neither are working. I tried to "force" the output with a [Number] component initially (since that typically works) with no success. I also tried your suggestion, but I get the following runtime error:

Runtime error (ValueErrorException): invalid literal for float(): n/a

Traceback:
line 1, in script

Hopefully the image clarifies.

/SPM

Du you get all but a few of the numbers converted?

Could you provide the whole input list?

Do you have any exotic locale set? (though GH seems to eat decimal commas as well as points)

/ola

Check Naruto's reply. Seems like you are trying to iterate through "x" list, but you haven't set it up as a list, in the first place.

It's either that, or you have some invalid value in your input (like <null>).
Please attach your .gh file in the future.

You need to select a list

Attachments:

I solved the issue, thanks to djordje pointing out the obvious. I already tried all of the standard and suggested solutions (hinted input 'x' as List Access, etc.), but I had a few invalid items in the CSV.

Thanks for the help. I appreciate all your responses.

Cheers,

/SPM

P.S. djordje: I like to make the alterations personally (helps me learn/understand what I'm doing), which is why I withhold my definitions unless requested. Although I totally understand the need for one to dig into the file. I will post all necessary files with my next discussion. Thanks.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service