I'm trying to change self.var_1
in the code below from another class, but I receive the error test1 has no attribute 'var_1'
. I feel like I'm making a simple mistake but can't seem to find the issue.
class test1:
def __init__(self):
self.var_1 = "bob"
instance2 = test2()
def change_var(self, new_var):
print(self.var_1) #should print "bob"
self.var_1 = new_var #should change "bob" to "john"
print(self.var_1) #should print "john"
class test2:
def __init__(self):
test1.change_var(test1, "john")
instance = test1()