Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Queue' object has no attribute 'size'
    primarykey
    data
    text
    <p>I have seen other examples of this happening on StackOverflow, but I didn't understand any of the answers (I'm still a new programmer,) nor did the other examples I saw look quite like mine, else I wouldn't post this question.</p> <p>I'm running Python 3.2 on Windows 7.</p> <p>I have never had this happen to me before and I've done classes this way many times, so I don't really know what is different this time. The only difference is that I didn't make all of the Class file; I was given a template to fill in and a test file to try it on. It worked on the test file, but is not working on my file. I have been calling on the methods in the class in the exact same way as the test file (e.g. Lineup.size())</p> <p>This is my Class:</p> <pre> class Queue: # Constructor, which creates a new empty queue: def __init__(self): self.__items = [] # Adds a new item to the back of the queue, and returns nothing: def queue(self, item): self.__items.insert(0,item) return # Removes and returns the front-most item in the queue. # Returns nothing if the queue is empty. def dequeue(self): if len(self.__items) == 0: return None else: return self.__items.pop() # Returns the front-most item in the queue, and DOES NOT change the queue. def peek(self): if len(self.__items) == 0: return None else: return self.__items[(len(self.__items)-1)] # Returns True if the queue is empty, and False otherwise: def is_empty(self): return len(self.__items) == 0 # Returns the number of items in the queue: def size(self): return len(self.__items) # Removes all items from the queue, and sets the size to 0: def clear(self): del self.__items[0:len(self.__items)] return # Returns a string representation of the queue: def __str__(self): return "".join(str(i) for i in self.__items) </pre> <p>This is my program:</p> <pre><code>from queue import Queue Lineup = Queue() while True: decision = str(input("Add, Serve, or Exit: ")).lower() if decision == "add": if Lineup.size() == 3: print("There cannot be more than three people in line.") continue else: person = str(input("Enter the name of the person to add: ")) Lineup.queue(person) continue elif decision == "serve": if Lineup.is_empty() == True: print("The lineup is already empty.") continue else: print("%s has been served."%Lineup.peek()) Lineup.dequeue() continue elif (decision == "exit") or (decision == "quit"): break else: print("%s is not a valid command.") continue </code></pre> <p>And this is my error message when I enter "add" as my decision variable:</p> <p><em>line 8, in builtins.AttributeError: 'Queue' object has no attribute 'size'</em></p> <p>So, what is going on here? What is different about this one?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload