During creating fme list I get python error:
Attempts from my side:
and:
and even this:
maybe the issue with data in my python list (data) ? but it is just array which contain text data.
During creating fme list I get python error:
Attempts from my side:
and:
and even this:
maybe the issue with data in my python list (data) ? but it is just array which contain text data.
This is how I would create an fme list on a feature from a python list
import fme
import fmeobjects
def processFeature(feature):
mylist = b"apple","banana","cherry"]
for i, val in enumerate(mylist):
feature.setAttribute("list{"+str(i)+"}.fruit", val)
This is how I would create an fme list on a feature from a python list
import fme
import fmeobjects
def processFeature(feature):
mylist = b"apple","banana","cherry"]
for i, val in enumerate(mylist):
feature.setAttribute("list{"+str(i)+"}.fruit", val)
thanks for suggestion, but problem is still the same
thanks for suggestion, but problem is still the same
If each item in your list is an array, you will need to convert the array to a string to write it to an attribute value
Hi @pavelpostnov, in general, the <TypeError> occurs with the setAttribute method if the data type of the attribute value you have set is not supported in the method. See this document to see what types are supported in the method.
fmeobjects.FMEFeature.setAttribute
According to the code snippets shown in your screenshot, I guess each element of the "data" list is a Python dictionary object, which is not supported as an attribute value to be added to the feature directly. If you intend to store a Python dictionary object as a JSON text into a feature attribute, consider using the dumps method from the json module. See here to learn more.
json — JSON encoder and decoder
Example:
data = n
{"A":1, "B":2},
{"A":3, "B":4}
]
from json import dumps
feature.setAttribute('_list{}', "dumps(d) for d in data])
Hi, I think for the list in list, it should be written like this:
feature.setAttribute("_pages{%s}._list_in_list{}" %(int(length)-1), datanlength-1])
I wrote an article exactly talking about this, may you take a look and hope it can help you: https://www.linkedin.com/pulse/terminator-fme-trick-can-solve-95-gis-vector-data-scenarios-miles-lee/
Hi @pavelpostnov, in general, the <TypeError> occurs with the setAttribute method if the data type of the attribute value you have set is not supported in the method. See this document to see what types are supported in the method.
fmeobjects.FMEFeature.setAttribute
According to the code snippets shown in your screenshot, I guess each element of the "data" list is a Python dictionary object, which is not supported as an attribute value to be added to the feature directly. If you intend to store a Python dictionary object as a JSON text into a feature attribute, consider using the dumps method from the json module. See here to learn more.
json — JSON encoder and decoder
Example:
data = n
{"A":1, "B":2},
{"A":3, "B":4}
]
from json import dumps
feature.setAttribute('_list{}', "dumps(d) for d in data])
Thanks, a lot. Yes, it was related to my data type in the my python list.