Skip to main content

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

Hi judychang,

 

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

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


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.


Reply