Let's say we call a constructor expression:
account2 = Account('John Paul', Decimal('-1234'))
The class definition has an initialization method of:
def __init__(self, name, balance):
if balance < Decimal('0.00'):
raise ValueError
self.name = name
self.balance = balance
In our constructor expression call the balance is negative and a ValueError
is raised by the __init__
method.
If I then try to reference the variable account I get a NameError
from my REPL. However, doesn't the class object have to be instantiated for that reference 'self' to be passed into __init__
for the initialization method to run in the first place?
I think that Python is reacting correctly, but I'm a tad confused how Python works in the background.