Skip to main content
How can I set a list attribute in Python? I can access the list by something like:

 

for i in range(0, numberFeatures):             subscript = "lstGrouped(%s).STRATA_UNIT_AREA" % i              oneStrataUnitArea = int(feature.getAttribute(subscript))

 

 

...but when I try to set the attribute, FME makes a new list:

 

 

for i in range(0, numberFeatures):             feature.setAttribute("lstGrouped(" + str(i) + ").STRATA_UNIT_AREA",str(oneStrataUnitArea))

 

I can make a new list and expose it on the canvas, but FME does not treat it as a real list. That is, I can't explode a list that I made in Python.

 

 

Thanks
Hi,   The list index should be enclosed by {}. Try this: ---- for i in range(numberFeatures):     feature.setAttribute("lstGrouped{%d}.STRATA_UNIT_AREA" % i, str(oneStrataUnitArea)) ----

 

Takashi
You are right, it should be curly braces, not parentheses. But when you use getAttribute, you use parentheses.

 

 

Thanks.
You can use {} (curly braces) when using getAttribute. I think it's usual manner in FME Python scripting.

 

Additionally, you can get all the elements of a list attribute as a string list at once.

 

list = feature.getAttribute("lstGrouped{}.STRATA_UNIT_AREA")

 

 

Takashi
Actually I was wrong about the parentheses in getAttribute(). You can use them and it will not raise an exception, but to get the value of a given subscript, you have to use curly braces.

Reply