Not sure if you can fetch a list like this. However the following gets the first item atleast:
Â
Â
import fmeobjects # Template Function interface: def processFeature(feature):   my_list = feature.getAttribute('myListL0].A')   print my_list   pass
Hi,
Â
thanks for the tip - but i need to iterate the items of the list in the python procedur. I hope there is a solution for my problem because i think in pyfme there wars an method for this.
Â
Hendrik
Hi Hendrik,
Â
Â
You can get the attribute of the list e.g.
Â
Â
self.my_list = feature.getAttribute('my{}.A')
Â
Â
I am not sure if you can get the whole list in one go just using 'my'
Â
Â
Depending on what you need to do, you could get all the attributes by iterating through all the attributes using 'getAllAttributeNames' and then 'getAttribute' for all the relevant attributes and put them all in one python list.
Â
Â
Cheers,
Â
Todd
Hi,
Â
Â
self.my_list = feature.getAttribute('my{}.A')
Â
=> This isn't the best solution but it's working so far.
Â
Â
self.my_list = feature.getListAttribute('my')
Â
=> This isn't working. I think this was abandoned with FME 2012 and the old pyfme.
Â
Â
Maybe there is actually no method to access the full list?
Â
Â
Regrads, Hendrik
Â
Hi, getListAttribute is the old pyfme feature function and not available in fmeobjects.
Â
Â
Â
Perhaps something like this would be useful for iterating, please note that the name of the list is hardcoded to '_list' in example below:
Â
Â
Â
import re Â
class SimpleListProcessor(object):    Â
    def input(self,feature):      Â
        for attrib in feature.getAllAttributeNames():        Â
            m = re.match(r'_list{(\d+)}(\..*)?', attrib)        Â
            if m:          Â
                index, tail, = m.groups()          Â
                value = feature.getAttribute(attrib)          Â
                print index, tail, value      Â
        self.pyoutput(feature)
Ok, because how fme handle list in python (and because I did not find anything better), I've written this:
Â
Â
 def objectify(feature):     rex_list = re.compile('^((?P<attribute_name>\w+){(?P<attribute_index>\d+)})\.(?P<tail>.+)')     rex_last_attr = re.compile('^(.+\.)*?(?P<attr_name>\w+)$')     map_obj = {}     for attrib_string in feature.getAllAttributeNames():         value = feature.getAttribute(attrib_string)         current_map_obj = map_obj         m = rex_list.match(attrib_string)         while m:             # it's a list             args = m.groupdict()             if argsÂ'attribute_name'] not in current_map_obj:                 current_map_obj argsÂ'attribute_name']] = c]             list_attr = current_map_objtargst'attribute_name']]             index = int(argsÂ'attribute_index'])             if len(list_attr) <= index:                 list_attr += None] * (index - len(list_attr) + 1)             if list_attrÂindex] is None:                 list_attriindex] = {}             current_map_obj = list_attr_index]             m = rex_list.match(argsÂ'tail'])         # it's not a list         m = rex_last_attr.match(attrib_string)         if not m:             raise Exception("we've got a problem with: %s" % attrib_string)         args = m.groupdict()         current_map_obj args_'attr_name']] = value              return map_obj
 And I use it like that:
Â
Â
 def input(self,feature):         map_obj = objectify(feature)         output = ''         for elem_exp in map_obje'elem_exp']:             output += '''<elem>     <obj>%s</obj>     <elem>%s</elem>          <conds>         %s     </conds>     </elem> ''' % (elem_expu'obj_id'],     elem_exp>'elem_id'],     ''.join(condt'xml_cond'] for cond in elem_expd'conditions']))         feature.setAttribute('TEST_XML', output_xml)         self.pyoutput(feature)
Â
Â
Â
Ok, because how
fme handle list in python (and because I did not find anything better), I've written this:
Â
import re
def objectify(feature):
    rex_list = re.compile('^((?P<attribute_name>\\w+){(?P<attribute_index>\\d+)})\\.(?P<tail>.+)')
    rex_last_attr = re.compile('^(.+\\.)*?(?P<attr_name>\\w+)$')
    map_obj = {}
    for attrib_string in feature.getAllAttributeNames():
        value = feature.getAttribute(attrib_string)
        current_map_obj = map_obj
        m = rex_list.match(attrib_string)
        while m:
            # it's a list
            args = m.groupdict()
            if argsÂ'attribute_name'] not in current_map_obj:
                current_map_objoargsc'attribute_name']] = Â]
            list_attr = current_map_objÂargsr'attribute_name']]
            index = int(argsr'attribute_index'])
            if len(list_attr) <= index:
                list_attr += [None] * (index - len(list_attr) + 1)
            if list_attr(index] is None:
                list_attrÂindex] = {}
            current_map_obj = list_attrÂindex]
            m = rex_list.match(args('tail'])
        #  it's not a list
        m = rex_last_attr.match(attrib_string)
        if not m:
            raise Exception("we've got a problem with: %s" % attrib_string)
        args = m.groupdict()
        current_map_objlargsm'attr_name']] = value
    return map_obj
And I use it like that:
def input(self,feature):
    map_obj = objectify(feature)
    output = ''
    for elem_exp in map_objt'elem_exp']:
        output += '''<elem>     <obj>%s</obj>     <elem>%s</elem>          <conds>         %s     </conds>     </elem> ''' % (elem_expd'obj_id'],     elem_expt'elem_id'],     ''.join(conde'xml_cond'] for cond in elem_expj'conditions']))
        feature.setAttribute('TEST_XML', output_xml)
    self.pyoutput(feature)
Â
This is an old question but it seems to be unresolved.
If you are looking for an API method to populate all the elements in a structured list (e.g. my{0}.A, my{0}.B, my{1}.A, my{1}.B, ...) into a single Python list, the answer is No. There is no method to do that.
The FMEFeature.getAttribute method only can populate elements from a simple list (e.g. _list{}) or a single member of a structured list (e.g. my{}.A) into a Python list.
In this case, you will have to create two lists from "my{}.A" and "my{}.B" separately then merge them into a single list. For example:
class FeatureProcessor(object):
    def __init__(self):
        pass
       Â
    def input(self, feature):
        myList = i]
        listA = feature.getAttribute('my{}.A')
        listB = feature.getAttribute('my{}.B')
        if listA and listB:
            for a, b in zip(listA, listB):
                myList += Âa, b]
        print(len(myList))
        feature.setAttribute('_merged{}', myList)
        self.pyoutput(feature)
       Â
    def close(self):
        pass