Skip to main content
Solved

Expose attributes in Python Caller


mr_fme
Enthusiast
Forum|alt.badge.img+8

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.  

View original
Did this help you find an answer to your question?

6 replies

takashi
Influencer
  • 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+8
  • 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
Influencer
  • November 1, 2023
mr_fme wrote:

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+8
  • Author
  • Enthusiast
  • November 1, 2023
takashi wrote:

Write within the "processFeature" function, like this.

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

 

No work, unfortunately.

 

image


takashi
Influencer
  • November 1, 2023
takashi wrote:

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+8
  • Author
  • Enthusiast
  • November 1, 2023
takashi wrote:

Write within the "processFeature" function, like this.

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

 

Thank´s


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings