Question

Replaceing output value to new dataframe

  • 3 February 2020
  • 3 replies
  • 4 views

Hi there,

I use Python caller to run Python script in FME. Python caller reads the data and generates a new data frame (with more attributes) after performing calculations. Now I want to output the new data frame and do not display the old data (that is feeding as input to Python Caller). I am not sure how to do that. Any help would be really appreciated.


3 replies

Badge

Are you just removing columns and creating new ones so 10 records in and 10 out, or creating more or less records, so 10 records in and 5 out?

It's more record coming in and less record going out

Badge

This is when you use the self to store that values you want to create in the close section as the init / self values are global variables.

The code below is the same as a group by with a sum total of the value

import fmeobjects
import fme

class FeatureProcessor(object):
    def __init__(self):
# create my store of values
        self.featureStore = {}
    def input(self,feature):
        Group = feature.getAttribute("ColA")
        Value = feature.getAttribute("ColB")
# if the value exists in the store then add the value otherwise create a new value in the store
        try:
            CurrentValue = self.featureStore[Group]
            self.featureStore[Group] = CurrentValue + Value
        except KeyError:
            self.featureStore[Group] = CurrentVal

    def close(self):
# loop through the store and create the new features
        for group, value in self.featureStore.items():
            newFeature = fmeobjects.FMEFeature()
            newFeature.setAttribute("NewColA", group)
            newFeature.setAttribute("NewColB", value )
            self.pyoutput(newFeature)

Also remember you will need to show and hide the correct attributes.

Reply