Skip to main content
Solved

update a (global) variable in a PythonCaller and use it in another PythonCaller

  • June 4, 2023
  • 1 reply
  • 138 views

Forum|alt.badge.img

Dear all, 

 

I am facing the following issue - sounds very simple : I have a 2-column table that gives a mapping oldname->newname that I store in a dictionnary inside a PythonCaller ; in another PythonCaller, I need to use this dictionary.

So far, I am doing the following : 

1) in Python Start-up script, I define a global variable

global mydict
mydict = {}

2) in the 1st PythonCaller : I populate a dictionary in the `input`function and then in the `close`function , I update the value of the global`all_progs` 

class FeatureProcessor(object):
    def __init__(self):
        tmpdict={}
        pass
    def input(self,feature):
        # do something like :
        tmpdict['oldname'] = 'newname'
 
    def close(self):
        mydict = tmpdict
        pass

3) in the 2nd PythonCaller I would like to use this dictionary ; but when I try iterating over the dict `mydict` in the 2nd PythonCaller, it looks empty...

 

What am I doing wrong ? How could I pass the values from a PythonCaller to another ? 

 

Should I put something in the part "Attributes to Expose" for updating a global Python variable ? (I've tried several things, but sofar without success...)

 

Thanks in advance for any suggestion

Best answer by david_r

Try something like this:

    class FeatureProcessor(object):
        def __init__(self):
            pass
 
        def input(self,feature):
            global mydict
            mydict['oldname'] = 'newname'
     
        def close(self):
            pass

 

View original
Did this help you find an answer to your question?

1 reply

david_r
Celebrity
  • Best Answer
  • June 5, 2023

Try something like this:

    class FeatureProcessor(object):
        def __init__(self):
            pass
 
        def input(self,feature):
            global mydict
            mydict['oldname'] = 'newname'
     
        def close(self):
            pass

 


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