Would it be possible to create a script in one PythonCaller with a number of functions, and then call the functions in that script from another PythonCaller using the 'from <script_name> import <function_name>' syntax?
Yes, you can, but not exactly as you propose. For example, you can import modules that are saved in the same directory as your workspace file. This works because FME automatically adds the current workspace directory to the PythonPath when the workspace is running. This is also mentioned in the log.
Since the entire workspace is using the same Python interpreter, it is also possible to reference objects between different PythonCallers, but there are some potential pitfalls so this is something that I always try to avoid.
But as an example, you can define a global variable in the startup script and retrieve the value in e.g. a PythonCaller later on.
Thanks @david_r for your quick reply. What would be some of the pitfalls of referencing objects between different PythonCallers? Also, when you talk about defining a global variable in the startup script and retrieving it in the PythonCaller, how would I do that when the variable is another PythonCaller?
Thanks @david_r for your quick reply. What would be some of the pitfalls of referencing objects between different PythonCallers? Also, when you talk about defining a global variable in the startup script and retrieving it in the PythonCaller, how would I do that when the variable is another PythonCaller?
Pitfalls would be scope and order of execution, amongst other thing. But this is not something I have tested extensively.
I believe you can define a global variable in one PythonCaller and reference it in another, but it's not a very elegant or transparent solution, I find.
ok great thank you for explaining!