Skip to main content
Solved

Get some attribute names with python

  • February 15, 2018
  • 3 replies
  • 56 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

 

 

Best answer by carsonlam

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())
View original
Did this help you find an answer to your question?

3 replies

carsonlam
Safer
Forum|alt.badge.img
  • Safer
  • Best Answer
  • February 15, 2018

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 wrote:

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.

 


david_r
Celebrity
  • February 16, 2018
carsonlam wrote:

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_')]

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings