Python Forum
" Run constructors" instead of the correct line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
" Run constructors" instead of the correct line
#1
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
Reply
#2
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.
Reply
#3
Thank you!

I added :

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Do all class need constructors?(__init__) hsunteik 13 9,311 May-02-2017, 09:36 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020