Skip to main content
Question

Get attribute names with Python to a column in Excel

  • May 17, 2016
  • 4 replies
  • 39 views

Forum|alt.badge.img

I am trying to get attribute names from multiple input MapInfo files into one column in Excel with PythonCaller.

I can get it to print in the Log but it doesn't go out to the Excel reader. Not too sure what the problem is - I use the script below:

import fmeobjects

def processFeature(feature):

pass

class FeatureProcessor(object):

def __init__(self):

pass

def input(self,feature):

feature.removeAttrsWithPrefix('mapinfo_') feature.removeAttrsWithPrefix('fme_') feature.removeAttrsWithPrefix('multi_')

attrNames = feature.getAllAttributeNames()

inputAttrNames = []

for attrname in attrNames: inputAttrNames.append(attrname)

feature.setAttribute('_inputAttrNames', inputAttrNames) self.pyoutput(feature)

def close(self): pass

I have also tried in the for loop -

for attrname in attrNames:

feature.setAttribute('_inputAttrNames', attrname)

Thanks!!

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.

4 replies

Forum|alt.badge.img+7

Hi judychang,

 

Just a small question. Did you expose the newly created attribute in the PythonCaller?

david_r
Celebrity
  • May 17, 2016

Hi

Rather than struggling with Python, have you looked at the AttributeExploder? The contents of the "_attr_name" attribute should be what you're looking for.

You can then use a Tester to skip those starting with "fme_" etc.

David


Forum|alt.badge.img
  • Author
  • May 17, 2016

Hi judychang,

 

Just a small question. Did you expose the newly created attribute in the PythonCaller?

Hi @jeroenstiers, yes I did. I think it's to do with data structure - when I tested for a constant feature.setAttribute('_inputAttrNames', 'test') it worked.


Forum|alt.badge.img
  • Author
  • May 17, 2016

Hi

Rather than struggling with Python, have you looked at the AttributeExploder? The contents of the "_attr_name" attribute should be what you're looking for.

You can then use a Tester to skip those starting with "fme_" etc.

David

Hi @david_r,

Thank you! That's what I was looking for.