Skip to main content

I have a PythonCaller with an input function as usual.

 

In this function, I have a list to update.
myList = rtoto, tata] if cond1: 	myList.remove(toto)
logger1  myList.append(momo)
logger2 if cond2:
myList.remove(tata)
logger3
myList.append(mama)
logger4

So, I want to obtain at last, myList = Âmomo, mama]

 

But, if I check the loggers : 

 

logger1 : Itata] (all right)

 

logger2 : ltata, momo] (still all right)

 

logger3 : Âtoto] (as if the list reseted)

 

logger4 : ototo, mama] (so not quite good)

I think the problem come from the fact that I have two objects coming in the FME project. Is that right?

How can I save the first change?

Am I missing something?

 

I suspect this question would be more suitable in a Python forum.

Anyway, it's difficult to help unless you post the whole code and tell us precisely what you want to achieve.


I think you are mixing up local and global variables, but please post your whole code so we can see what's going wrong.


I suspect this question would be more suitable in a Python forum.

Anyway, it's difficult to help unless you post the whole code and tell us precisely what you want to achieve.

def input(self,feature):

...

myAnswerField = .('Echelle1', None), ('Echelle2', None)]  if '01' in feature.getAttribute('id_reseau'):
            scale1 = feature.getAttribute('echellesortieplanprincipal')
            myAnswerFields.remove(('Echelle1', None))
            myAnswerFields.append(('Echelle1', scale1))
        if '02' in feature.getAttribute('id_reseau'):
            scale2 = feature.getAttribute('echellesortieplanprincipal')
            myAnswerFields.remove(('Echelle2', None))
            myAnswerFields.append(('Echelle2', scale2))

 
with this database : 

 

0684Q00000ArMXTQA3.png


I suspect this question would be more suitable in a Python forum.

Anyway, it's difficult to help unless you post the whole code and tell us precisely what you want to achieve.

I thought it was a PythonCaller problem actually. Maybe I misunderstood.

 


I thought it was a PythonCaller problem actually. Maybe I misunderstood.

 

The way the PythonCaller works is pretty simple and it is coherent with the way Python (and most OOP languagues) work in this type of pattern:

 

 

  • Before the first feature arrives: call __init__() once
  • For each feature: call input() once per feature
  • After the last feature has passed: call close() once
You may want to read up a bit on Python objects and particulary on scope, e.g. here. I agree with @verdoodtdries that it looks like a scoping error.

 

 

I do not quite understand what you really want to achieve, but I suspect you want to make myAnswerField an object instance variable (rather than a local variable, as it is now). You can do this by initalizing myAnswerField in __init__() and prefixing it with "self." whenever you reference it.

 

 

As it is you are effectively resetting (redefining) myAnswerField for every incoming feature, that may not be what you want?
The way the PythonCaller works is pretty simple and it is coherent with the way Python (and most OOP languagues) work in this type of pattern:

 

 

  • Before the first feature arrives: call __init__() once
  • For each feature: call input() once per feature
  • After the last feature has passed: call close() once
You may want to read up a bit on Python objects and particulary on scope, e.g. here. I agree with @verdoodtdries that it looks like a scoping error.

 

 

I do not quite understand what you really want to achieve, but I suspect you want to make myAnswerField an object instance variable (rather than a local variable, as it is now). You can do this by initalizing myAnswerField in __init__() and prefixing it with "self." whenever you reference it.

 

 

As it is you are effectively resetting (redefining) myAnswerField for every incoming feature, that may not be what you want?
Ok, I understand. And you both are right for intention in this context. I'll try. Thanks.

 

 


The way the PythonCaller works is pretty simple and it is coherent with the way Python (and most OOP languagues) work in this type of pattern:

 

 

  • Before the first feature arrives: call __init__() once
  • For each feature: call input() once per feature
  • After the last feature has passed: call close() once
You may want to read up a bit on Python objects and particulary on scope, e.g. here. I agree with @verdoodtdries that it looks like a scoping error.

 

 

I do not quite understand what you really want to achieve, but I suspect you want to make myAnswerField an object instance variable (rather than a local variable, as it is now). You can do this by initalizing myAnswerField in __init__() and prefixing it with "self." whenever you reference it.

 

 

As it is you are effectively resetting (redefining) myAnswerField for every incoming feature, that may not be what you want?
Ok, it's seems that I should have just one feature in the input instead of 2. A colleague of mine helped me on that. So problem solved.

 

Thanks anyway. I have a better understanding of the PythonCller thanks to you.

 

 


Reply