I am writing a program that will at some point procedurally generate a new version of itself, save it to a file, and then import it from that file, overwriting relevant classes by the imported ones. And by saying that I mean the whole class will be redefined, not just specific methods changed.
So my question is, what happens to the already created instances of this class while it is redefined? Suppose you have:
class FooType():
def __init__(self):
pass
def doSomething(self):
print("Hello from old FooType")
foo = FooType()
# some code is executed here
class FooType():
def __init__(self, bar=None):
self.bar = bar if bar is not None else 'lorem ipsum'
def doSomething(self):
print("Hello world")
def somethingNew(self):
print("Hey, I can do this now!")
foo.doSomething()
which gives:
Hello from old FooType
meaning the foo object has not been updated, but why?