By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,470 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,470 IT Pros & Developers. It's quick & easy.

Bound method error

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. -----------------------------------------
  2. from Queue import Queue
  3.  
  4. Q=Queue()
  5. inp=raw_input("Skriv indata: ")
  6. indata=inp.split(" ")
  7. i=0
  8. while i<len(indata):
  9.     Q.put(indata[i])
  10.     i=i+1
  11.  
  12. print Q.isempty
  13.  
  14. ----------------------------------------
  15.  
  16. from Node import Node
  17. class Queue:
  18.     front=None
  19.     back=None
  20.  
  21.     def put(self, x):
  22.         new=Node()
  23.         new.value=x
  24.         if self.front is None:
  25.             self.front=new
  26.             self.back=new
  27.         else:
  28.             self.back.next=new
  29.             self.back=new
  30.  
  31.     def get(self):
  32.         x=self.front
  33.         self.front=self.front.next
  34.         return x
  35.  
  36.     def isempty(self):
  37.         return self.front==None
  38.  
  39. -----------------------------------------------
  40.  
  41. class Node:
  42.     value=None
  43.     next=None
Mar 2 '08 #1
Share this Question
Share on Google+
4 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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:
Expand|Select|Wrap|Line Numbers
  1. -----------------------------------------
  2. from Queue import Queue
  3.  
  4. Q=Queue()
  5. inp=raw_input("Skriv indata: ")
  6. indata=inp.split(" ")
  7. i=0
  8. while i<len(indata):
  9.     Q.put(indata[i])
  10.     i=i+1
  11.  
  12. print Q.isempty
  13.  
  14. ----------------------------------------
  15.  
  16. from Node import Node
  17. class Queue:
  18.     front=None
  19.     back=None
  20.  
  21.     def put(self, x):
  22.         new=Node()
  23.         new.value=x
  24.         if self.front is None:
  25.             self.front=new
  26.             self.back=new
  27.         else:
  28.             self.back.next=new
  29.             self.back=new
  30.  
  31.     def get(self):
  32.         x=self.front
  33.         self.front=self.front.next
  34.         return x
  35.  
  36.     def isempty(self):
  37.         return self.front==None
  38.  
  39. -----------------------------------------------
  40.  
  41. class Node:
  42.     value=None
  43.     next=None
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__.Queue instance at 0x00F84CB0>>

Try this:
Expand|Select|Wrap|Line Numbers
  1. >>> Q.isempty()
  2. False
  3. >>> 
Mar 3 '08 #2

P: 2
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__.Queue instance at 0x00F84CB0>>

Try this:
Expand|Select|Wrap|Line Numbers
  1. >>> Q.isempty()
  2. False
  3. >>> 

Oh of course. And calling methods without () means basically nothing?
Mar 3 '08 #3

bvdet
Expert Mod 2.5K+
P: 2,851
Oh of course. And calling methods without () means basically nothing?
No. It returns the bound method which can be assigned to a variable.
Mar 3 '08 #4

P: 1
@bvdet
i have occur a bound method error in grade and result.

Expand|Select|Wrap|Line Numbers
  1. class student:
  2.     def getStudent(self):
  3.         self.name = input("Name: ")
  4.         self.Roll = int(input("Roll: "))
  5.  
  6. class test(student):
  7.  
  8.     def getMarks(self):
  9.         print("Enter the marks of the respective subjects")
  10.         self.literature = int(input("Literature: "))
  11.         self.math = int(input("Math: "))
  12.         self.biology = int(input("Biology: "))
  13.         self.physics = int(input("Physics: "))
  14.         self.chemistry=int(input("chemistry:"))
  15.     def average(self):
  16.         average = Total/500
  17.         return average
  18.     def Grade(self):
  19.         if self.average >=85:
  20.             self.Grade="S"
  21.         elif self.average >=75:
  22.             self.Grade="A"
  23.         elif self.average >=65:
  24.             self.Grade="B"
  25.         elif self.average >=55:
  26.             self.Grade="C"
  27.         elif self.average >=50:
  28.             self.Grade="D"
  29.         else:
  30.             self.Grade="F"
  31.  
  32.     def Result(self):
  33.        if marks==5:
  34.             self.Result="PASS"
  35.        if marks>=3:
  36.             self.Result="COMP"
  37.        else:
  38.             self.Result="FAIL"
  39.             return Result
  40.  
  41. class marks(test):
  42.     def display(self):
  43.         print("\n\nName: ",self.name)
  44.         print("Roll : ",self.Roll)
  45.         print("Total Marks: ", self.literature + self.math + self.biology + self.physics + self.chemistry)
  46.         print("Average:",self.literature + self.math + self.biology + self.physics + self.chemistry /500)
  47.         print "Grade:",self.Grade()
  48.         print "Result:",self.Result()
  49.  
  50. obj = marks()
  51. obj.getStudent()
  52. obj.getMarks()
  53. obj.display()
1 Week Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.