Skip to main content
Question

Get attribute names with Python to a column in Excel


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!!

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
Evangelist
  • 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
jeroenstiers wrote:

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

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.


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