I have a file that does some analysis of the object that I pass to it
something like that:
test.py
:
class Test: var_array = [] def add_var(self, new_var): self.var_array.append(new_var) def run(test): for var in test.var_array: print var
I have another file where I define the information I want to process
test2.py
:
import os import sys TEST_DIR = os.path.dirname(os.path.abspath(__file__)) if TEST_DIR not in sys.path: sys.path.append(TEST_DIR) from test import * test = Test() test.add_var('foo') run(test)
so if i run this several times
In [1]: %run test2.py foo In [2]: %run test2.py foo foo In [3]: %run test2.py foo foo foo
What am I doing wrong? Should test = Test()
create a new instance of the object?
source share