Skip to main content
Question

How can I utilize a custom python script inside a PythonCreator?

  • August 14, 2020
  • 5 replies
  • 45 views

Forum|alt.badge.img

Hello,

I have integrated a custom script into a PythonCreator. The PythonCreator executes the code and accomplishes what it is supposed to do, but at the end I get an error message and I'm unsure how to get rid of it. Please see attached screen shot. Any assistance would be greatly appreciated.

 

Thank you!

FmeError

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

takashi
Celebrity
  • August 15, 2020

Hi @david_allan​ , from this error message, it seems that you are attempting to call a function called "tester()" with passing an argument but the function can take no arguments.

 

Python Exception <TypeError>: tester() takes 0 positional arguments but 1 was given

 

Check the definition of the function "tester()" and call it correctly.


Forum|alt.badge.img

Hi @david_allan​ , from this error message, it seems that you are attempting to call a function called "tester()" with passing an argument but the function can take no arguments.

 

Python Exception <TypeError>: tester() takes 0 positional arguments but 1 was given

 

Check the definition of the function "tester()" and call it correctly.

Thanks for the reply @takashi​ . I checked the function name and they seem to match. I have attached a screen shot of a simple function that I am calling. When the Python Creator runs, the print statement prints, but I receive the <TypeError> message. Is it possible to run custom python scripts within Python Creators/Callers?FmeError


ebygomm
Influencer
Forum|alt.badge.img+45
  • Influencer
  • August 18, 2020

Thanks for the reply @takashi​ . I checked the function name and they seem to match. I have attached a screen shot of a simple function that I am calling. When the Python Creator runs, the print statement prints, but I receive the <TypeError> message. Is it possible to run custom python scripts within Python Creators/Callers?FmeError

I think you need to use the FME class template as a starting point (although don't quote me on that!)

import os
import sys
 
def execute():
    print ("Hello World")
 
class FeatureCreator(object):
    def __init__(self):
        pass
    def input(self,feature):
        pass
    def close(self):
        if __name__ == '__main__':
            execute()

 


jeand
Contributor
Forum|alt.badge.img+5
  • Contributor
  • August 19, 2020

@david_prosack88​ 

The issue is the parameter for [Class to Process Features]. You use directly the function [execute] and it's not legit.

The class or the function you want to use with PythonCaller must respect one of these pattern:

If you want to call a Method, the signature must be: [Function Name](feature):

def execute(feature):

pass #Enter your code here. Every features that pass through here will be output.

If you want to call a Class, the signature must be:

class MyClass(object):

def input(self):

pass #This is the constructor called only one time.

def input(self, feature):

self.pyoutput(feature) #Let out the incomming feature. So you need to add lines before for any logical things to do.

#self.pyoutput let you decide if you want or not to let the feature to out.

def close(self):

pass #Called only once when no other features will incomming in this PythonCaller.

 

Hope this information will help you out.

 

Jean


takashi
Celebrity
  • August 20, 2020

Thanks for the reply @takashi​ . I checked the function name and they seem to match. I have attached a screen shot of a simple function that I am calling. When the Python Creator runs, the print statement prints, but I receive the <TypeError> message. Is it possible to run custom python scripts within Python Creators/Callers?FmeError

Could you please share the script you wrote in the PythonCreator with us?​