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:

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

for r in refs: 
	section_name = "test"

OUT = refs

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

I received this error.

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()

Still got the error

I guess this is not the way haha:

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()

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”


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

1 Like

Thanks for you’re help :slight_smile: