return a list to be referred in the session through python script?

Hi,

I couldn’t figure this out and am going to use the example below to better describe my question.
When I execute the code below in the script editor, I will get listA = [1, 2, 3] printed and the listA can be referred throughout the current session.

Code:

listA = [1,2,3]
print 'listA = ', listA


To integrate the code as a python script, I wrap the code as a function as below:

Code:

def testFunc():
    listA = [1,2,3]
    print 'listA = ', listA
    return listA


and modify the menu.py so I can execute the python script upon button-pushing.

As I execute the python script, I did get the listA = [1,2,3] printed in the script editor, but if I try to refer to the listA again by executing, say, print listA, I will get:

Code:

# Result: Traceback (most recent call last):  File "<string>", line 1, in <module>
 NameError: name 'listA' is not defined


What I want to achieve is generating a list storing wanted information through the python script so I can refer to over and over again in the same session. Any comment?

Thanks,
Jason

No Responses to “return a list to be referred in the session through python script?”

Post a Comment