Hi,
The getAllAttributeNames method returns a list containing all attribute names which the feature has. For example, this script creates a concatenated attribute names and assign it to a new attribute. Try this and check the result to know the functionality of the method.
def processFeature(feature):
    attrNames = ','.join(feature.getAllAttributeNames())
    feature.setAttribute('attrNames', attrNames)
Takashi
Hi,
The getAllAttributeNames method returns a list containing all attribute names which the feature has. For example, this script creates a concatenated attribute names and assign it to a new attribute. Try this and check the result to know the functionality of the method.
def processFeature(feature):
    attrNames = ','.join(feature.getAllAttributeNames())
    feature.setAttribute('attrNames', attrNames)
Takashi
@takashi Thanks your help.Â
I used in my Workspace and its works.
Thanks!
Danilo de Lima
Hi,
The getAllAttributeNames method returns a list containing all attribute names which the feature has. For example, this script creates a concatenated attribute names and assign it to a new attribute. Try this and check the result to know the functionality of the method.
def processFeature(feature):
    attrNames = ','.join(feature.getAllAttributeNames())
    feature.setAttribute('attrNames', attrNames)
Takashi
@takashiÂ
i have this attribute: atts_names: safe,danilo, inovacao
And i would like to remove the word danilo from my attribute atts_names? Using python
Thanks
@takashiÂ
i have this attribute: atts_names: safe,danilo, inovacao
And i would like to remove the word danilo from my attribute atts_names? Using python
Thanks
There may be various approaches. e.g.
# Use List
def processFeature(feature):
    src = feature.getAttribute('attr_names')
    if src:
        attrNames = Â]
        for attr in str(src).split(','):
            if attr.strip() != 'danilo':
                attrNames.append(attr)
        feature.setAttribute('attr_names', ','.join(attrNames))
# Use Regular Expression
import re
def processFeature(feature):
    src = feature.getAttribute('attr_names')
    if src:
        repl = lambda m: ',' if m.group(1) and m.group(2) else ''
        feature.setAttribute('attr_names', re.sub(r'(,?)\s*danilo\s*(,?)', repl, str(src)))
Regarding Python language, please learn with web sites or books.
BTW, why not use the StringReplacer?
- Attributes:Â attr_names
- Text to Match: (,\s*danilo\s*|\s*danilo\s*,|\s*danilo\s*)
- Replacement Text: <blank>
- Use Regular Expressions: yes
"No Coding Required" (in most cases) is an advantage of FME ;)
Hi,
The getAllAttributeNames method returns a list containing all attribute names which the feature has. For example, this script creates a concatenated attribute names and assign it to a new attribute. Try this and check the result to know the functionality of the method.
def processFeature(feature):
    attrNames = ','.join(feature.getAllAttributeNames())
    feature.setAttribute('attrNames', attrNames)
Takashi
@tasashi
Hi,
This method doesn't seem to work for me. I am trying to get all the attribute names from my input MapInfo files from a generic "schema" reader.Â
I am using FME2013 and I have also tried with the followings and nothing seemed to have worked.Â
feature.getListAttribute ('attribute{}.name') - this gives me a generic out put of w'zmap_max_x', 'zmap_max_y', 'zmap_min_x', 'zmap_min_y', 'zmap_null_value']
feature.getAttribute ('attribute{}.name')
I'm new to python and hopefully this description makes sense. Thanks!
@tasashi
Hi,
This method doesn't seem to work for me. I am trying to get all the attribute names from my input MapInfo files from a generic "schema" reader.
I am using FME2013 and I have also tried with the followings and nothing seemed to have worked.
feature.getListAttribute ('attribute{}.name') - this gives me a generic out put of ['zmap_max_x', 'zmap_max_y', 'zmap_min_x', 'zmap_min_y', 'zmap_null_value']
feature.getAttribute ('attribute{}.name')
I'm new to python and hopefully this description makes sense. Thanks!
Hi @judychang, FME Objects Python API has been upgrated in 2012, and the "getListAttribute" is a method in the old API. I don't remember the exact behavior of PythonCaller in FME 2013, but perhaps it still can work with the old API. See also this article: New Python FME Objects API in FME 2012
Hi @judychang, FME Objects Python API has been upgrated in 2012, and the "getListAttribute" is a method in the old API. I don't remember the exact behavior of PythonCaller in FME 2013, but perhaps it still can work with the old API. See also this article: New Python FME Objects API in FME 2012
Thanks. My getListAttribute works if I use import pyfme but not if I use import fmeobjects..
@tasashi
Hi,
This method doesn't seem to work for me. I am trying to get all the attribute names from my input MapInfo files from a generic "schema" reader.
I am using FME2013 and I have also tried with the followings and nothing seemed to have worked.
feature.getListAttribute ('attribute{}.name') - this gives me a generic out put of ['zmap_max_x', 'zmap_max_y', 'zmap_min_x', 'zmap_min_y', 'zmap_null_value']
feature.getAttribute ('attribute{}.name')
I'm new to python and hopefully this description makes sense. Thanks!