Skip to main content
Question

Replaceing output value to new dataframe

  • February 3, 2020
  • 3 replies
  • 43 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.

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.

3 replies

Forum|alt.badge.img
  • 48 replies
  • February 4, 2020

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?


  • Author
  • 30 replies
  • February 4, 2020

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


Forum|alt.badge.img
  • 48 replies
  • February 5, 2020

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.