You can create attributes anywhere you wish. The error with your code is that you did not invoke method Bye
before you tried to print an attribute that is created only within that method. Instead, try
prop = Compliment()
print(prop.Hello)
prop.Bye()
print(prop.bye)
In answer to your direct question: no, you cannot make __init__
useless for creating attributes. You do not have to use it that way, but you cannot disable it: __init__
is a language-defined method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…