Skip to main content
Question

How to call my own defined function in pythoncaller?

  • September 26, 2018
  • 4 replies
  • 134 views

When I call the function convert I wrote, I get the error "PythonNameError: global name 'convert' is not not defined"

4 replies

david_r
Celebrity
  • September 26, 2018

How did you define "convert" in your Python code?

Also, have you looked at the PythonCaller documentation?


lifalin2016
Contributor
Forum|alt.badge.img+29
  • Contributor
  • September 27, 2018

Additional Python libraries needs to be installed in your FME instances, typically under (FME_HOME)/python/python27 (for old Python). Each library needs to include the standard "__init__.py" file to be recognized, afaik.

Have a look at the standard libraries installed.

If it's for a custom transformer, a companion PY file stored side-by-side will also do the trick.


  • Author
  • September 27, 2018
david_r wrote:

How did you define "convert" in your Python code?

Also, have you looked at the PythonCaller documentation?

 

a simple function

 

def convert():

 

FMELogFile().logMessageString('ddd')

 

This function is defined in the class FeatureProcessor(object) and is called inside the close() function.

david_r
Celebrity
  • September 27, 2018

You need to make it a class method, since you're using it as part of an object (class instance). For example, inside the FeatureProcessor definition:

def convert(self):
    FMELogFile().logMessageString('ddd'

Notice the "self" parameter. Then in the close() function you write:

 

self.convert()


For more information, see the Python documentation on how to define class methods.

This tutorial is also pretty helpful: https://www.learnpython.org/en/Classes_and_Objects


Reply


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