Python Forum
" Run constructors" instead of the correct line - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: " Run constructors" instead of the correct line (/thread-29325.html)



" Run constructors" instead of the correct line - MaartenRo - Aug-28-2020

Hi,

I am trying to run this code. Somehow it shows " Run constructors" instead of the line " Hallo daar!". What am i doing wrong?

Any input is much appreciated!




class MyClass:
    Greeting = ""
    
    def __init__(self, Name="daar"):
        self.Greeting = Name + "!"
        
    def SayHello(self):
        print("Hallo {0}".format(self.Greeting))
>>> %Run constructors.py



RE: " Run constructors" instead of the correct line - ndc85430 - Aug-28-2020

For a start, there's only a class definition in that code; nowhere actually instantiated the class and calls the SayHello method. Secondly, in the second snippet it looks like you're trying to run the code from within a Python shell. That's not right either.


RE: " Run constructors" instead of the correct line - MaartenRo - Aug-28-2020

Thank you!

I added :

>>> MyInstance = MyClass()
>>> MyInstance.SayHello()
and now it works.