How to deal with list in python?

Hi all,

What is the right way to deal with lists in Python?
I’ve seen a lot of topics but it’s not clear to me.

For example, I want a parameter vlaue of this pipes:

#geconnecte pipe ophalen
refs = []

for x in pipe_fitting:
	connset = x.MEPModel.ConnectorManager.Connectors
	conn_pipes = []
	for c in connset:
		if c.IsConnected:
			for lc in c.AllRefs:
				conn_pipes.append(lc.Owner)
	refs.append(conn_pipes)

#section van buis ophalen
s_names = []
keys = []

for r in refs: 
	section_name = "test"
	keys.append(section_name)	

OUT = refs

When I change the “test” in section_name = r.get_Parameter(RDB.BuiltInParameter.RBS_SECTION).AsValueString()

I received this error.
image

I know that I need to look deeper but what is the best way?
I have the same problem with grouping and set parameter values

Try putting it in a loop.
So you’re trying to get the parameter of each element in the list, rather than asking for the parameter of a list.

Like this?

for r in refs: 
	for x in refs:
		for y in refs:
			section_name = y.get_Parameter(RDB.BuiltInParameter.RBS_SECTION).AsValueString()
			keys.append(section_name)

Still got the error

I guess this is not the way haha:
image

Did you get the same error when you added the extra loops?

I’m still a beginner in Python but I know your error says you’re feeding it a list and the way round that is to add a loop. I’m sure someone more qualified will be along soon but in the mean time have you tried breaking the thing you’re looping down in a different way? I usually find copying the bit that’s not working to a fresh Python node and working out exactly what I am feeding it what it’s spitting out at what stage helps.

You never believe this… haha

for r in refs: 
	for i in r:
		section_name = i.get_Parameter(RDB.BuiltInParameter.RBS_SECTION).AsValueString()
		keys.append(section_name)		

The problem was not the loop but the refs.
I did this:

for r in refs: 
	for x in refs:

But the refs is “r” so the next loop need to be “for i in r”

2 Likes

Haha!! I should have spotted that too. :laughing:
Glad you fixed it :slight_smile:

1 Like

Thanks for you’re help :slight_smile: