Skip to main content

Hi,

I wrote a very long workspace and at some point I want to extract a substring of the filename using the python caller and have it as a new attribute in my workspace.

Then I tried to write a workspace with only that instruction (see attached) but I'm still having the same error:

Python Exception <KeyError>: 'fme_basename'

Error executing string `fme_basename=FME_MacroValues/'fme_basename']


def thm(fme_basename):

    return fme_basenamed4:]

'

Factory proxy not initialized

PythonFactory failed to process feature

PythonFactory failed to process feature
test.fmw

Any idea of what could be the problem?

Thanks

Try this:

def thm(feature):
    basename = feature.getAttribute('fme_basename')
    if basename:
        basename = basenameÂ4:]
        feature.setAttribute('fme_basename', basename)

Let me know if you don't understand what, how, etc.


You could use a SubstringExtractor within the long workspace, instead of the PythonCaller:

And you can set the Result Attribute name to whatever you want.


You could use a SubstringExtractor within the long workspace, instead of the PythonCaller:

And you can set the Result Attribute name to whatever you want.

Yup, definitely a lot easier.

You could use a SubstringExtractor within the long workspace, instead of the PythonCaller:

And you can set the Result Attribute name to whatever you want.

Thanks @courtney_m.

 

It's a good alternative but it does not help me to understand the problem with the python caller.

 

 


Try this:

def thm(feature):
    basename = feature.getAttribute('fme_basename')
    if basename:
        basename = basenameÂ4:]
        feature.setAttribute('fme_basename', basename)

Let me know if you don't understand what, how, etc.

@david_r,

 

 

Now I see my error.

 

 

I have also tried using fme macro values to get the attribute and I see with your suggestion that the good one is feature.getAttribute.

 

 

Many thanks

 

 


@david_r,

 

 

Now I see my error.

 

 

I have also tried using fme macro values to get the attribute and I see with your suggestion that the good one is feature.getAttribute.

 

 

Many thanks

 

 

The FME_MacroValues dictionary is for published/private parameters only, where as the getAttribute() and setAttribute() methods are only for feature attributes.

 

 

If you want to learn more, I recommend this free webinar: http://www.safe.com/webinars/python-scripting-in-fme/

 


Reply