Skip to main content

Hello All,

I would like to use python to get the attribute name from a feature. The API Documentation i found the Class FME Feature - getAllAttributesNames().

I my pythoncaller is:

import fme

import fmeobjects

def processFeature(feature):

atributo = getAllAttributesNames()

pass

But doenst work.

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 ;)


Thanks again @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

@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!


Reply