Solved

Get some attribute names with python

  • 15 February 2018
  • 3 replies
  • 29 views

Hello all,

I have a pythonCaller in my script where I am populating an array with all the attribute names from the feature

test_fields = feature.getAllAttributeNames()

how do I go about excluding any fme generated features (example: fme_feature_type). I can't quite work out the syntax. Any help will be appreciated. Thanks

 

 

icon

Best answer by carsonlam 15 February 2018, 22:49

View original

3 replies

Badge

Attributes added by FME usually have a prefix of "fme_", so this is one way to exclude them:


test_fields = filter(lambda name: not name.startswith('fme_'), feature.getAllAttributeNames())

Attributes added by FME usually have a prefix of "fme_", so this is one way to exclude them:


test_fields = filter(lambda name: not name.startswith('fme_'), feature.getAllAttributeNames())
@carsonlam you are a life saver! Thank you so much! That is such a simple solution. I was battling with conditional statements.

 

Userlevel 4

Attributes added by FME usually have a prefix of "fme_", so this is one way to exclude them:


test_fields = filter(lambda name: not name.startswith('fme_'), feature.getAllAttributeNames())
Great answer by Carson. Here's the same thing using list comprehension:

 

test_fields = [x for x in feature.getAllAttributeNames() if not x.startswith('fme_')]

Reply