Say I have this code:
class hello_world():
def define_hello(self):
self.hello = "hello"
def say_hello(self):
print self.hello
class change_to_goodbye():
def __init__(self):
self.helloWorld = hello_world()
def hello_to_goodbye(self):
self.helloWorld.hello = "goodbye"
class other_class():
def __init__(self):
self.helloWorld = hello_world()
self.changeToGoodbye = change_to_goodbye()
self.helloWorld.define_hello()
self.changeToGoodbye.hello_to_goodbye()
self.helloWorld.say_hello()
oc = other_class()
Class hello_world has two methods, one that defines the variable hello and one that prints it. On the other hand, class change_to_goodbye tries to access the variable hello in class hello_world and changes it to goodbye. Class other_class should set the variable hello to "hello", change it to "goodbye", and print it on the screen.
I expected the output to be "goodbye" but I got "hello". Why isn't change_to_goodbye changing the variable of hello_world?