Skip to main content
Solved

Expose value Python Caller

  • October 20, 2024
  • 2 replies
  • 59 views

mr_fme
Enthusiast
Forum|alt.badge.img+9

Hi,

How can I expose the result (print), like attribute in python caller:

 

        from_value = min_iten[0]['from']
        to_value = min_iten[0]['to']
        print(f"{from_value[:-10]}")

 

Thank´s

Best answer by hkingsbury

You need to use the setAttribute() function on the feature object, then set that new attribute to be exposed.

 

Your input function should therefore look like:

    def input(self, feature: fmeobjects.FMEFeature):
"""This method is called for each feature which enters the PythonCaller.
Processed input features can be emitted from this method using self.pyoutput().
If knowledge of all input features is required for processing, then input features should be
cached to a list instance variable and processed using group processing or in the close() method.
"""

from_value = min_iten[0]['from']
to_value = min_iten[0]['to']

feature.setAttribute('attributeName',f"{from_value[:-10]}")

self.pyoutput(feature)

And at the bottom of the PythonCaller, expose your attribute like so:
 

 

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.

2 replies

hkingsbury
Celebrity
Forum|alt.badge.img+65
  • Celebrity
  • Best Answer
  • October 20, 2024

You need to use the setAttribute() function on the feature object, then set that new attribute to be exposed.

 

Your input function should therefore look like:

    def input(self, feature: fmeobjects.FMEFeature):
"""This method is called for each feature which enters the PythonCaller.
Processed input features can be emitted from this method using self.pyoutput().
If knowledge of all input features is required for processing, then input features should be
cached to a list instance variable and processed using group processing or in the close() method.
"""

from_value = min_iten[0]['from']
to_value = min_iten[0]['to']

feature.setAttribute('attributeName',f"{from_value[:-10]}")

self.pyoutput(feature)

And at the bottom of the PythonCaller, expose your attribute like so:
 

 


mr_fme
Enthusiast
Forum|alt.badge.img+9
  • Author
  • Enthusiast
  • October 21, 2024

Thank´s @hkingsbury