Bound method error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohanCarlstrom
    New Member
    • Mar 2008
    • 2

    Bound method error

    I get bound method error (for method isempty) when trying to run this code. I have coded python for about 2 hours so Im a little lost...
    Also, if someone could post source the code of any small program consisting of multiple classes and objects, it would surely be a great help for me.


    Code:
    Code:
    -----------------------------------------
    from Queue import Queue
    
    Q=Queue()
    inp=raw_input("Skriv indata: ")
    indata=inp.split(" ")
    i=0
    while i<len(indata):
        Q.put(indata[i])
        i=i+1
    
    print Q.isempty
    
    ----------------------------------------
    
    from Node import Node
    class Queue:
        front=None
        back=None
    
        def put(self, x):
            new=Node()
            new.value=x
            if self.front is None:
                self.front=new
                self.back=new
            else:
                self.back.next=new
                self.back=new
    
        def get(self):
            x=self.front
            self.front=self.front.next
            return x
    
        def isempty(self):
            return self.front==None
    
    -----------------------------------------------
    
    class Node:
        value=None
        next=None
    Last edited by gits; Mar 19 '20, 02:27 PM. Reason: added code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by JohanCarlstrom
    I get bound method error (for method isempty) when trying to run this code. I have coded python for about 2 hours so Im a little lost...
    Also, if someone could post source the code of any small program consisting of multiple classes and objects, it would surely be a great help for me.


    Code:
    [code=Python]
    -----------------------------------------
    from Queue import Queue

    Q=Queue()
    inp=raw_input(" Skriv indata: ")
    indata=inp.spli t(" ")
    i=0
    while i<len(indata):
    Q.put(indata[i])
    i=i+1

    print Q.isempty

    ----------------------------------------

    from Node import Node
    class Queue:
    front=None
    back=None

    def put(self, x):
    new=Node()
    new.value=x
    if self.front is None:
    self.front=new
    self.back=new
    else:
    self.back.next= new
    self.back=new

    def get(self):
    x=self.front
    self.front=self .front.next
    return x

    def isempty(self):
    return self.front==Non e

    -----------------------------------------------

    class Node:
    value=None
    next=None[/code]
    I ran your code but did not receive an error. Statement print Q.isempty returned what it was supposed to:
    <bound method Queue.isempty of <__main__.Que ue instance at 0x00F84CB0>>

    Try this:
    [code=Python]
    >>> Q.isempty()
    False
    >>> [/code]

    Comment

    • JohanCarlstrom
      New Member
      • Mar 2008
      • 2

      #3
      Originally posted by bvdet
      I ran your code but did not receive an error. Statement print Q.isempty returned what it was supposed to:
      <bound method Queue.isempty of <__main__.Que ue instance at 0x00F84CB0>>

      Try this:
      [code=Python]
      >>> Q.isempty()
      False
      >>> [/code]

      Oh of course. And calling methods without () means basically nothing?

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Originally posted by JohanCarlstrom
        Oh of course. And calling methods without () means basically nothing?
        No. It returns the bound method which can be assigned to a variable.

        Comment

        • swarna98
          New Member
          • Mar 2020
          • 1

          #5
          student marklist

          Originally posted by bvdet
          No. It returns the bound method which can be assigned to a variable.
          i have occur a bound method error in grade and result.

          Code:
          class student:
              def getStudent(self):
                  self.name = input("Name: ")
                  self.Roll = int(input("Roll: "))
                  
          class test(student):
              
              def getMarks(self):
                  print("Enter the marks of the respective subjects")
                  self.literature = int(input("Literature: "))
                  self.math = int(input("Math: "))
                  self.biology = int(input("Biology: "))
                  self.physics = int(input("Physics: "))
                  self.chemistry=int(input("chemistry:"))
              def average(self):
                  average = Total/500
                  return average
              def Grade(self):
                  if self.average >=85:
                      self.Grade="S"
                  elif self.average >=75:
                      self.Grade="A"
                  elif self.average >=65:
                      self.Grade="B"
                  elif self.average >=55:
                      self.Grade="C"
                  elif self.average >=50:
                      self.Grade="D"
                  else:
                      self.Grade="F"
                  
              def Result(self):
                 if marks==5:
                      self.Result="PASS"
                 if marks>=3:
                      self.Result="COMP"
                 else:
                      self.Result="FAIL"
                      return Result
               
          class marks(test):
              def display(self):
                  print("\n\nName: ",self.name)
                  print("Roll : ",self.Roll)
                  print("Total Marks: ", self.literature + self.math + self.biology + self.physics + self.chemistry)
                  print("Average:",self.literature + self.math + self.biology + self.physics + self.chemistry /500)
                  print "Grade:",self.Grade()
                  print "Result:",self.Result()
              
          obj = marks()
          obj.getStudent()
          obj.getMarks()
          obj.display()
          Last edited by gits; Mar 19 '20, 02:26 PM. Reason: added code tags

          Comment

          • hussainmujtaba
            New Member
            • Apr 2020
            • 13

            #6
            Code:
            class student:
                def getStudent(self):
                    self.name = input("Name: ")
                    self.Roll = int(input("Roll: "))
             
            class test(student):
             
                def getMarks(self):
                    print("Enter the marks of the respective subjects")
                    self.literature = int(input("Literature: "))
                    self.math = int(input("Math: "))
                    self.biology = int(input("Biology: "))
                    self.physics = int(input("Physics: "))
                    self.chemistry=int(input("chemistry:"))
                def average(self):
                    Total=self.literature + self.math + self.biology + self.physics + self.chemistry
                    average = Total/500
                    return average
                def Grade(self):
                    if self.average() >=85:
                        self.Grade="S"
                    elif self.average() >=75:
                        self.Grade="A"
                    elif self.average() >=65:
                        self.Grade="B"
                    elif self.average() >=55:
                        self.Grade="C"
                    elif self.average()>=50:
                        self.Grade="D"
                    else:
                        self.Grade="F"
                    return self.Grade
             
                def Result(self):
                    marks=self.literature + self.math + self.biology + self.physics + self.chemistry
                    if marks==5:
                        self.Result="PASS"
                    if marks>=3:
                        self.Result="COMP"
                    else:
                        self.Result="FAIL"
                    return self.Result
             
            class marks(test):
                def display(self):
                    print("\n\nName: ",self.name)
                    print("Roll : ",self.Roll)
                    print("Total Marks: ", self.literature + self.math + self.biology + self.physics + self.chemistry)
                    print("Average:",self.literature + self.math + self.biology + self.physics + self.chemistry /500)
                    print("Grade:",self.Grade())
                    print("Result:",self.Result())
             
            obj = marks()
            obj.getStudent()
            obj.getMarks()
            obj.display()
            This code will work fine. There were quite basic bugs in there.
            Last edited by Rabbit; Sep 1 '20, 03:42 PM.

            Comment

            Working...