python problem running in Bash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hhlaing
    New Member
    • Jan 2008
    • 4

    #1

    python problem running in Bash

    Hello,

    I am running the following codes in Bash. And it is complaining about class. Could someone please see why?

    #!/usr/bin/python
    #Message codes

    import sys

    class Message:
    def _init_(self, aString):
    self.text = aString
    def printIt(self):
    print self.text

    def main( argv = sys.argv):
    m1 = Message("Hello World")
    m2 = Message("so long, it was short but sweet")

    note = [m1, m2]

    for msg in note:
    msg.printIt()
  • tdob
    New Member
    • Oct 2007
    • 4

    #2
    hi,

    I found 2 errors in your code;

    - constructor must be prefixed and suffixed with 2 uderscores ( __init__ )
    - you must to call the method main for the execution of your code

    regards,
    tdob


    Originally posted by hhlaing
    Hello,

    I am running the following codes in Bash. And it is complaining about class. Could someone please see why?

    #!/usr/bin/python
    #Message codes

    import sys

    class Message:
    def _init_(self, aString):
    self.text = aString
    def printIt(self):
    print self.text

    def main( argv = sys.argv):
    m1 = Message("Hello World")
    m2 = Message("so long, it was short but sweet")

    note = [m1, m2]

    for msg in note:
    msg.printIt()

    Comment

    Working...