print "value is",value
Then look for it in the log file. An internal line by line step through debugger would be useful, or to use an external editor that has a line by line step through debugger, enable PyScripter to understand:
import fme
import fmeobjects
There is already an article about using the excellent PyCharm IDE with FME: Use PyCharm as FMEObjects Python IDE
Would that work for your use case?
On a more general note, I've had a lot of success with writing my modules as generic as possible, without using FMEobjects at all, only simple Pythonic data structures. It is then easy to integrate them into PythonCallers etc, using only a minimum of code to extract the necessary feature info (coordinates and/or key attributes) into they datastructures and pass them on to the modules. The great thing about this is the possibility of doing unit testing etc on your modules without having to rely on either FME or specific data.
David
Python is very powerfull but in FME (PythonCaller or PythonCreator) we need to have a real debugger.
In many cases, there is a indentation issue (grr), may be the best solution in the transformer is to use a better indentation for the Python language.
It will be very fun to debug the python scrypt with a Point break when the workbench is running
Suggestion to have two output for the PythonCaller or Creator:
- Output: everything works fine
- Output: exceptions
It's really easy to simulate the two output ports, though:
try:# Process feature here...
feature.setAttribute('_error', 0)
except:
feature.setAttribute('_error', 1)
Then you check for '_error' using e.g. a Tester.
David
If you use PyScripter.You can configure it like this
- Tools ?Edit Startup Scripts
- Add the following code:
import sys
fmePypath=[r"C:\\apps\\FME\\fmeobjects\\python27",r"C:\\apps\\FME\\plugins",r"C:\\apps\\FME\\python",r"C:\\apps\\FME\\python\\python27"]
sys.path.extend(fmePypath)
- Restart PyScripter
PyScripter will be able to understand fmeobjects
'
This is a good solution but you would still be running your Python script outside of FME, correct? Everytime you work on your script and get it to work you would have to copy it and put it into the PythonCaller in your FME script. What I had in mind was that you open the PythonCaller and there is an option to open that script in your favorite IDE. When you save it in the IDE it saves to the PythonCaller.
One way I have emulated this is to write my code in my external Python editor and then import it in the PythonCaller.
import myPythonScript
If the script is in the same folder as the FME script or is on the PYTHONPATH, the FME Python interpreter will find it and execute it.
This is great to know about PyScripter. However, as I understand it, you would still be testing your script externally to FME and then you would have to copy it into the PythonCaller, correct?
See my comments to David's suggestion about PyCharm above.
I also use the "import myPythonModule" paradigm, it works nicely.
It also has the added benefit of forcing you to separate the algorithm (module) from your data (workspace), which I think is generally a good idea in itself.
Unit testing and debugging is also much easier when working on a free standing module, rather than integrated into e.g. a PythonCaller.
I use PyCharm and liked very much.
Yes i know that :)
Thank you !
Yes to a new IDE!
But also these lines are very usefull:
logger = fmeobjects.FMELogFile()logger.logMessageString('Black_Info',0)
logger.logMessageString(‘Blue_Warning’,1)
logger.logMessageString('Red_Error',2)
Quick suggestion - a save button within the PythonCaller and PythonCreator that saves the workbench.
Integrating the open source Atom would be great! https://atom.io/
Out of the few python IDEs I have used, pyScripter gets my vote for ease of use and also potential incorporation into FME Desktop. PyCharm might be too much of a sledgehammer.
Yes please!
I was just going to create this post and was so glad there already was one with so many votes. Yes please :)
Over a thousand votes and still getting recent comments. Clearly there is user interest in this. 7 years since the idea was proposed, so also clearly there is a problem or two in implementing it. Would someone from Safe please provide some information on what gets in the way of using {IDE_of_choice}* for FME python scripts? There are some capable people in the user base. Maybe a description of the challenge to be surmounted will elicit some ideas or even code for doing so.
* my personal vote is Pyzo. Lightweight, self contained, easily switch between active interpreters without restarting, interactive and live variable exploration, cross platform.
Perhaps using our favorite Python software for developping?
https://community.safe.com/s/bridea/a0rDm000000Ccp7IAC/python-debugging
Pycharm would be great..