Skip to main content

Hello,

I've written a Python script that performs some data extraction and saves the results to a dictionary. I now need to expose these keys and values as attributes to FME.

My Python code is simply as follows:

feature = fmeobjects.FMEFeature()
for keys, values in row.items():
    feature.setAttribute(keys, values)
self.pyoutput(feature)

The only issue is that both the length of the dictionary and names of the key value pairs will be changing on a very regular basis. This essentially means that I do not have any fixed names that I can expose.

If possible, I'm looking for a solution such as assigning the attributes to a parameter and then passing this parameter to the 'Attributes to Expose' box within the Python Caller.

Is anything like this possible?

Thanks,

Jamie

Unfortunately not. There's no mechanism to dynamically expose attributes to use in the canvas.

If you only need to write out the attributes, you can create a dynamic schema, and even though they are never exposed on the canvas, they will still be present in the output.

 

If you need to use an attribute later in the canvas, you can dynamically dereference it to a known attribute name, and then process with that attribute.

It's not possible to dynamically expose attributes, as the attribute names to expose aren't decided before your workspace actully runs.

This question is fairly frequent and you'll find some fairly detailed answers and possible workarounds by searching, e.g.

https://knowledge.safe.com/questions/102590/question-of-the-week-dealing-with-an-unknown-or-dy.html

https://knowledge.safe.com/questions/32777/how-to-expose-all-attributes-in-generic-way-any-ma.html

https://knowledge.safe.com/questions/20345/dynamic-attribute-creation-and-expose.html

 


Reply