Skip to main content
Solved

Get some attribute names with python

  • Feb 15, 2018 9:36 PM UTC
  • 3 replies
  • 126 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
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

carsonlam
Safer
Forum|alt.badge.img+7
  • Safer
  • Best Answer
  • Feb 15, 2018 9:49 PM UTC

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.

 


david_r
Celebrity
  • Feb 16, 2018 8:29 AM UTC

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