Unfortunately you cannot read an FME list like that, you have to reference every child attribute.
Try something like:
names = feature.getAttribute("attribute{}.name")
data_types = feature.getAttribute("attribute{}.fme_data_type")
attributes = zip(names, data_types)
for (name, data_type) in attributes:
if "fme_varchar" in data_type:
# Do something
print(f"Attribute '{name}' is of type '{data_type}'")
Thank you! Here is my result. Any more input and comments are welcome. Is there maybe a better alternative than using the loop counter ‘i’?
def input(self, feature: fmeobjects.FMEFeature):
names = feature.getAttribute("attribute{}.name")
data_types = feature.getAttribute("attribute{}.fme_data_type")
attributes = zip(names, data_types)
delimiter = ""
i = 0
for (name, data_type) in attributes:
if "fme_varchar" in data_type:
#extract only numbers from datatype
temp = re.findall(r'\d+', data_type)
res = int(delimiter.join(temp))
# if column name longer than name, alter datatype
if len(name) > res:
res = len(name)
new_data_type = "fme_varchar(" + str(res) + ")"
feature.setAttribute("attribute{%d}.fme_data_type" % i, new_data_type)
i = i + 1
self.pyoutput(feature)