Question

I have a Python 2.7 script that takes command line arguments. I am trying to implement it in a PythonCaller but it doesn't seem to recognize "feature.getAttribute". I'm getting this error "Python Exception <NameError>: name 'feature' is not def

  • 17 November 2022
  • 3 replies
  • 6 views

Using an old version - 2019.1.3.1 with ArcGIS 2.7 compatability.

 

In my script I have where:

 

import fme

import fmeobjects

 

 if __name__ == "__main__":

   # Script parameters

   inputLayer = feature.get.Attribute('inputLayer')

   outputLocation = feature.getAttribute('outputLocation')

   outputName = feature.getAttribute('outputName')


3 replies

Sorry - the line

inputLayer = feature.get.Attribute('inputLayer')

 

is acually

inputLayer = feature.getAttribute('inputLayer')

Userlevel 4

You'll have to either use the expected method or the class interface, see https://community.safe.com/s/article/pythoncaller-transformer

 

Basically, your code should look something like:

import fme
import fmeobjects
 
def my_feature_processor(feature):
   # Script parameters
   inputLayer = feature.getAttribute('inputLayer')
   outputLocation = feature.getAttribute('outputLocation')
   outputName = feature.getAttribute('outputName')

You then have to tell the PythonCaller that your entry point is "my_feature_processor"

Thanks david_r,

That worked for me.

Reply