Syntax @Python(. [,]+) Arguments String The name of the module where the function resides. String The name of the Python function to call. String One or more arguments to pass to the Python function. Attribute values may be used as arguments by prefixing the attribute name with an ampersand ('&'). Description Note: This function is not supported by FME Base Edition. This FME function executes an arbitrary Python function, returning the result. It allows access to a complete procedural language with rich built-in primitives from within FME mapping files. Python procedures can be written to simplify tasks that are awkward to accomplish using standard mapping file syntax, and to allow users to extend FME to solve new problems. To use this function effectively, familiarity with the Python language is required. There are several sources of information available to assist in learning Python. The Internet has many Python sites - the official site is at http://www.python.org. Note: On Windows, FME includes a Python 2.7 interpreter, but will use an external Python installation if configured. FME does not ship with Python on Linux and Mac OS X - an external Python distribution must be present. Python Function ~~~~~~~~~~~~~~~ The Python function that Python calls must, at the very minimum, accept a feature object as its first parameter. By default, the feature is supplied as a pyfme.FMEFeature object for backward compatibility. The pyfme API is deprecated, and the fmeobjects module should be used whenever possible. To switch to the current fmeobjects API, add the following line to the mapping file code prior to calling @Python: DYNAMIC_FUNCTION_CONFIGURATION Python FMEOBJECTS This will result in the supplied feature being of type fmeobjects.FMEFeature. For further documentation on fmeobjects.FMEFeature's available methods, see $(FME_HOME)/fmeobjects/python/apidoc. Python functions called by @Python can, if desired, accept any number of optional arguments. Examples: # This function returns the contents of the test attribute. # The FME call looks like: # @Python(examples.noArgs) def noArgs(feature): return feature.getAttribute('test') # This function sets two integer attributes, and returns the sum # of two arguments. The FME call looks like: # @Python(examples.addAB,1,2) def addAB(feature,a,b): feature.setAttribute(int(a)) feature.setAttribute(int(b)) c = int(a) + int(b) return str(c) FME Objects Logging ~~~~~~~~~~~~~~~~~~~ It is possible to directly access the FME log file from a Python function via an FMELogfile object. Example: def logExample(feature, mymessage): import fmeobjects logger = fmeobjects.FMELogfile() logger.logMessageString(mymessage, fmeobjects.FME_INFORM) @Python( examples.logExample, "A message to log" ) Interpreter Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~ The following directives can be used to configure the Python interpreter that FME loads. FME_PYTHON_PATH A path to add to Python's sys.path array that controls module loading. Wrap the path with quotation marks if it contains white space. FME_PYTHON_IMPORT The name of a Python module to import. Note: The module must reside in a directory referenced by Python's sys.path array.