Skip to main content
Solved

Expose attributes in Python Caller

  • November 1, 2023
  • 6 replies
  • 571 views

mr_fme
Enthusiast
Forum|alt.badge.img+9

Hi,

 

My workspace attached only takes information from the Website and shows values in the log.

 

How Can I expose the response in attributes using Python caller?

 

Thank´s

Best answer by takashi

Hi @mr_fme​ ,

In the Python script, you can add a pair of name and vlaue to the input feature object as a feature attribute with FMEFeature.setAttribute method, as in:

 

feature.setAttribute(attribute name, attribute value)

 

Then, expose the attribute name with the "Attributes to Expose" parameter in the PythonCaller or with a subsequent AttributeExposer transformer, if necessary.  

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.

6 replies

takashi
Celebrity
  • Best Answer
  • November 1, 2023

Hi @mr_fme​ ,

In the Python script, you can add a pair of name and vlaue to the input feature object as a feature attribute with FMEFeature.setAttribute method, as in:

 

feature.setAttribute(attribute name, attribute value)

 

Then, expose the attribute name with the "Attributes to Expose" parameter in the PythonCaller or with a subsequent AttributeExposer transformer, if necessary.  


mr_fme
Enthusiast
Forum|alt.badge.img+9
  • Author
  • Enthusiast
  • November 1, 2023

Thank´s, but where I need to put it?

 

In begining...

Python Exception <NameError>: name 'feature' is not defined

 

In the final...

Python Exception <IndentationError>: unindent does not match any outer indentation level

 

 


takashi
Celebrity
  • November 1, 2023

Thank´s, but where I need to put it?

 

In begining...

Python Exception <NameError>: name 'feature' is not defined

 

In the final...

Python Exception <IndentationError>: unindent does not match any outer indentation level

 

 

Write within the "processFeature" function, like this.

def processFeature(feature):
    ...
    feature.setAttribute("example", 1)

 


mr_fme
Enthusiast
Forum|alt.badge.img+9
  • Author
  • Enthusiast
  • November 1, 2023

Write within the "processFeature" function, like this.

def processFeature(feature):
    ...
    feature.setAttribute("example", 1)

 

No work, unfortunately.

 

image


takashi
Celebrity
  • November 1, 2023

Write within the "processFeature" function, like this.

def processFeature(feature):
    ...
    feature.setAttribute("example", 1)

 

Make sure indentations of the script are correct. Note that a single tab and some spaces look like the same width, but those are different in the number of characters and could cause the error. 


mr_fme
Enthusiast
Forum|alt.badge.img+9
  • Author
  • Enthusiast
  • November 1, 2023

Write within the "processFeature" function, like this.

def processFeature(feature):
    ...
    feature.setAttribute("example", 1)

 

Thank´s