Skip to main content
Archived

PythonCaller: simple syntax checking

Related products:Transformers
danilo_fme
  • danilo_fme
    danilo_fme

geosander
This has probably been mentioned before, but I think it would be nice if the PythonCaller does some simple syntax checking (indents, variable names, typos etc.). It's always annoying to find out there was an unnecessary error in my code which caused the translation to fail and now I have to copy-paste my (sometimes long) code to an IDE and back again...

[I remember that in the past, you could write all your code in an external *.py file and refer to the classes and functions in the PythonCaller. If this could be reintroduced, that would also be helpful!]

10 replies

david_r
Celebrity
  • November 23, 2015
Hi

 

 

You can still write your code in an external module, something like

 

 

import my_module def FeatureProcessor(feature): my_module.performFunction(feature)

 

David

geosander
Forum|alt.badge.img+7
  • Author
  • November 23, 2015

There's always this possibility, yes, thanks! However, this module then needs to reside in the Python libs folder, doesn't it?


david_r
Celebrity
  • November 23, 2015

You can save the module in the same folder as your workspace too. Either as a .py file parallell to the workspace or in a subfolder as a package.

If you look closely in the FME log, you will see that it automatically adds the workspace folder to the PYTHONPATH when initializing the interpreter.

David


geosander
Forum|alt.badge.img+7
  • Author
  • November 23, 2015

Cool, thanks, good to know! I'll try it out soon! :)


takashi
Influencer
  • November 24, 2015

Hi @sander_s, addition to David's comment.

If you have defined a function/class in the external module (e.g. "my_module.py") conforming to the template shown in the "Python Script" parameter, it can be called directly from the script.

In the "Python Script" parameter, just import the module,

import my_module

and then specify the function/class name qualified by the module name (e.g. "my_module.myFunction") in the "Class or Function to Process Features" parameter.

It's not essential to qualify the name by module name if you use "from - import" to import the function/class.

from my_module import myFunction

Even if you have saved the "my_module.py" into an external directory, you can import it by adding the path to the "sys.path" list in the script.

import sys sys.path.append(r'C:\\my_python_modules')

 

from my_module import myFunction

Alternatively, you can also add the directory path to the PYTHONPATH environment variable in the system. If you do so, "sys.path.append..." can be omitted.

Various ways depending on the condition :-)


geosander
Forum|alt.badge.img+7
  • Author
  • November 24, 2015

Thanks @takashi! Considering the circumstances, I think I prefer the sys.path.append() method, so I'll go with that.


  • November 24, 2015

I think you can still do this by putting the path to your py folder in an environment variable named PYTHONPATH. Then in your Python Caller start with:

import myModule

Python will find that module on the PYTHONPATH and run it.


bruceharold
Contributor
Forum|alt.badge.img+17
  • Contributor
  • November 24, 2015
This is covered by the idea to include and IDE.

 


geosander
Forum|alt.badge.img+7
  • Author
  • November 24, 2015

Agreed, but I was first ;)

An integrated IDE would definitely be nice to have, but since that would be quite a project on itself, I thought that at least basic syntax checking would make a good first step in that direction.


LizAtSafe
Safer
Forum|alt.badge.img+15
  • Safer
  • April 5, 2025
Updated idea statusOpenArchived
Idea merged into:

All the votes from this idea have been transferred.

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings