May-18-2017, 12:04 PM
Hi, I have 2 classes and I want a method which is in the the 2nd class ('class2_method') to be able to access a class variable from the first class. However I need 'class2_method' to be run from a method in the first class('class1_method').
The following code works ok, 'class1_var1' is changed from "test" to "test2" using 'class2_method'.
"class2 instance has no attribute 'test' "
Please can anyone tell me what I am doing wrong? Thanks.
The following code works ok, 'class1_var1' is changed from "test" to "test2" using 'class2_method'.
class class1(): def class1_method(self): self.class1_var1 = "test" self.class2_init = class2() self.class2_init.class2_method() class class2(): def class2_method(self): test.class1_var1 = "test2" print test.class1_var1 test = class1() test.class1_method()However, if I save the two classes as a module file('class_tests). And then try to do the same thing as before like this:
class class1(): def class1_method(self): self.class1_var1 = "test" self.class2_init = class2() self.class2_init.class2_method() class class2(): def class2_method(self): test.class1_var1 = "test2" print test.class1_var1 import class_tests reload(class_tests) test = class_tests.class1() test.class1_method()I get this error:
"class2 instance has no attribute 'test' "
Please can anyone tell me what I am doing wrong? Thanks.