Skip to main content

Dear FME community, apologies up front for being a novice python user

I am trying to use the python caller transformer to execute an external .py file. However my external .py file does not have any classes therefore I don’t know what to do with the ‘Class to process features’ parameter in the transformer. If I run the python caller regardless, it executes my .py script fine, but crashes at the end with this error message “PythonFactory failed to load python symbol `FeatureProcessor'”. This is because I’m using the default ‘FeatureProcessor’ as my parameter for the “class to process features”, which I know is wrong.

My python script simply generates a JPG file and saves it to a directory.

I hope someone can assist and I haven’t totally missed the point.

Regards, Damian

Hi Damian, can you share your PythonCaller input? Also: do you want to run your .py for every feature that passes onto your PythonCaller, or do you have to run it only once per translation. If the latter: in the Navigator window you can set a Python shutdown/startup script (under Workspace Parameters > Scripting).


Try something like the following in your PythonCaller:

import fmeobjects
import my_python_file

def FeatureProcessor(feature):
my_python_file.my_function(feature)

This will call my_function() in the external Python file “my_python_file.py” for each incoming feature. The incoming feature, of type fmeobjects.FMEFeature, will be passed as a parameter.


Dear @joepk, @david_r , thank you for your responses.

@joepk, I only need to run my .py script once per translation. I have indeed successfully used the python startup script to run my file, however, i don’t need to execute my .py file every time I run my FME script. My preference is to use workspace parameters with user input so that I can choose when to run the .py file (not essential, but nice to have - my python script updates an external JPG map, but the map doesn’t need to be updated every time I run the FME script, only sometimes). My python caller input is below.

@david_r, thank you very much for your suggestion but my python caller doesn’t have any incoming features (described above).

Regards, Damian

import os

def run_script(script_path):

# Execute the script using execfile
exec(open(script_path, 'r').read())

script_to_run = "Q:\AoAM\Outputs\Images\JPGMap.py"

# Run the script
run_script(script_to_run)

 


If you do not want to run your python script every time you run this workspace and if it is not triggered by any event in your workspace, I would either omit it from the workspace and run it ‘manually’ or I would try to get the requirements for having to run the script into the workspace, in order to trigger it. 


Reply