I am trying to find a way to input data into the ghpython node from panels in order not to have to hard code the following information into the ghpython node:
families = {
“Williams” : {“Joe” : 44, “Ellie” : 43, “Bill” : 11},
“Rogers” : {“Michael” : 70, “Sally” : 69},
“Timson” : {“Tim” : 51, “Lisa” : 52, “Ryan” : 24}}
print(type(families))
I can’t set type to in the input on the ghpython node.
Any ideas?..
Michael Wickerson
I want to use the data with the One-liner snippet:
old = [x for x in families if any(y > age for y in families[x ].values())]
You can do this:
You should use " " or ’ ’ instead of “ ”, because the “pretty” quotes won’t be parsed by eval()
, since they are not used in Python to declare strings.
3 Likes
Genius, clear, cogent, concise, intelligent! Thank you! Michael Wickerson
those quotes have tricked me up before when reading AAD by Arturo Tedeschi.
Michael
Then set
globals()[foo] = bar
to set the variable name to families
2 Likes
One can also use the standard json
module for parsing a string to a dict:
210531_StringToDict_JSON_GHPython_00.gh (2.8 KB)
2 Likes