span8
span4
span8
span4
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.
@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,
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
i have this attribute:atts_names: 亚搏在线safe,danilo,inovacao
And i would like to remove the worddanilofrom my attributeatts_names?Using python
Thanks
There may be various approaches.e.g.
# Use Listdef 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 Expressionimport redef 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?
"No Coding Required"(in most cases) is an advantage of FME ;)
@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
Feature Compare Validation1 Answer
Use PythonCaller to get list of files in directory on FTP site6 Answers
Getting published parameters from within a python caller nested in several custom transformers1 Answer
Running PyQGIS in FME PythonCaller transformer?2 Answers
Run FMEFactoryPipeline repeatedly with PythonCaller2 Answers
© 2019 亚搏在线Safe Software Inc |Legal