Re: [Tutor] How to extract a float from an instancemethod call
by reading the exception you see that you pass function pointer instead of a value "KeyError: (>, >)" as if you just print pos.getX and not pos.getX(), you will see the exact output - <__main__.Position object at 0x4699490> .. Regards, Yaniv. - Original Message - > From: "Sydney Shall" > To: "Dave Angel" > Sent: Monday, April 8, 2013 5:49:50 PM > Subject: Re: [Tutor] How to extract a float from an instancemethod call > > > > On 08/04/2013 13:52, Dave Angel wrote: > > On 04/08/2013 08:40 AM, Sydney Shall wrote: > >> Hi, > >> I am learning Python. > >> > >> I use MAC OSX 10.6.8 > >> Python 2.7.3 > >> > >> I have been given a project to write a program involving random walks. > >> I have drafted a program which has passed all the static tests, but on > >> testing my program i get the following error message: > >> > >> > >> Traceback (most recent call last): > >>File "/Users/Sydney/Documents/6.00x Files/Problem > >> Sets/ProblemSet7/ps7 copy.py", line 303, in > >> testRobotMovement(StandardRobot, RectangularRoom) > >>File "ps7_verify_movement.py", line 12, in testRobotMovement > >>File "/Users/Sydney/Documents/6.00x Files/Problem > >> Sets/ProblemSet7/ps7 copy.py", line 285, in updatePositionAndClean > >> while self.room.isPositionInRoom(self.position) == False: > >>File "/Users/Sydney/Documents/6.00x Files/Problem > >> Sets/ProblemSet7/ps7 copy.py", line 163, in isPositionInRoom > >> return self.room[(x,y)] in self.room > >> KeyError: ( >> 0x4699490>>, >> 0x4699490>>) > >> >>> > >> > >> The program text referred to is the following, I give the whole module, > >> which is part of a larger program. > >> def isPositionInRoom(self, pos): > >> """ > >> Return True if pos is inside the room. > >> > >> pos: a Position object. > >> returns: True if pos is in the room, False otherwise. > >> """ > >> x = pos.getX > >> y = pos.getY > > > > You never show the code for Position.getX and Position.getY, but I'd > > expect they're methods that take no arguments. in that case, you need > > parens in order to call them. > > > >x = pos.getX() > >y = pos.getY() > > > >> return self.room[(x,y)] in self.room > >> > > > > a simple print of x and y could have revealed this as well. > > > > > Dear Dave, > Thanks for pointing out my mistake. I thought it would be some small > error on my part. > I had a print statement, but I could not correctly interpret the output. > It solves that problem. > > > > -- > Sydney Shall > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to extract a float from an instancemethod call
On 08/04/2013 13:52, Dave Angel wrote: On 04/08/2013 08:40 AM, Sydney Shall wrote: Hi, I am learning Python. I use MAC OSX 10.6.8 Python 2.7.3 I have been given a project to write a program involving random walks. I have drafted a program which has passed all the static tests, but on testing my program i get the following error message: Traceback (most recent call last): File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 303, in testRobotMovement(StandardRobot, RectangularRoom) File "ps7_verify_movement.py", line 12, in testRobotMovement File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 285, in updatePositionAndClean while self.room.isPositionInRoom(self.position) == False: File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 163, in isPositionInRoom return self.room[(x,y)] in self.room KeyError: (>, >) >>> The program text referred to is the following, I give the whole module, which is part of a larger program. def isPositionInRoom(self, pos): """ Return True if pos is inside the room. pos: a Position object. returns: True if pos is in the room, False otherwise. """ x = pos.getX y = pos.getY You never show the code for Position.getX and Position.getY, but I'd expect they're methods that take no arguments. in that case, you need parens in order to call them. x = pos.getX() y = pos.getY() return self.room[(x,y)] in self.room a simple print of x and y could have revealed this as well. Dear Dave, Thanks for pointing out my mistake. I thought it would be some small error on my part. I had a print statement, but I could not correctly interpret the output. It solves that problem. -- Sydney Shall ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to extract a float from an instancemethod call
Aha - another EdX 6.00 Python course student. > Traceback (most recent call last): >File "/Users/Sydney/Documents/6.00x Files/Problem > Sets/ProblemSet7/ps7 copy.py", line 303, in > testRobotMovement(StandardRobot, RectangularRoom) >File "ps7_verify_movement.py", line 12, in testRobotMovement >File "/Users/Sydney/Documents/6.00x Files/Problem > Sets/ProblemSet7/ps7 copy.py", line 285, in updatePositionAndClean > while self.room.isPositionInRoom(self.position) == False: >File "/Users/Sydney/Documents/6.00x Files/Problem > Sets/ProblemSet7/ps7 copy.py", line 163, in isPositionInRoom > return self.room[(x,y)] in self.room > KeyError: ( 0x4699490>>, 0x4699490>>) > >>> > > The program text referred to is the following, I give the whole module, > which is part of a larger program. > def isPositionInRoom(self, pos): > """ > Return True if pos is inside the room. > > pos: a Position object. > returns: True if pos is in the room, False otherwise. > """ > x = pos.getX > y = pos.getY > return self.room[(x,y)] in self.room You extract X and Y from the Position object using it's accessor methods. All you then need to do is check to ensure that both X and Y are >= zero and that both of them, when converted to an into, are less than room. width and room. height. This email and any attachment to it are confidential. Unless you are the intended recipient, you may not use, copy or disclose either the message or any information contained in the message. If you are not the intended recipient, you should delete this email and notify the sender immediately. Any views or opinions expressed in this email are those of the sender only, unless otherwise stated. All copyright in any Capita material in this email is reserved. All emails, incoming and outgoing, may be recorded by Capita and monitored for legitimate business purposes. Capita exclude all liability for any loss or damage arising or resulting from the receipt, use or transmission of this email to the fullest extent permitted by law. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to extract a float from an instancemethod call
On 04/08/2013 08:40 AM, Sydney Shall wrote: Hi, I am learning Python. I use MAC OSX 10.6.8 Python 2.7.3 I have been given a project to write a program involving random walks. I have drafted a program which has passed all the static tests, but on testing my program i get the following error message: Traceback (most recent call last): File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 303, in testRobotMovement(StandardRobot, RectangularRoom) File "ps7_verify_movement.py", line 12, in testRobotMovement File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 285, in updatePositionAndClean while self.room.isPositionInRoom(self.position) == False: File "/Users/Sydney/Documents/6.00x Files/Problem Sets/ProblemSet7/ps7 copy.py", line 163, in isPositionInRoom return self.room[(x,y)] in self.room KeyError: (>, >) >>> The program text referred to is the following, I give the whole module, which is part of a larger program. def isPositionInRoom(self, pos): """ Return True if pos is inside the room. pos: a Position object. returns: True if pos is in the room, False otherwise. """ x = pos.getX y = pos.getY You never show the code for Position.getX and Position.getY, but I'd expect they're methods that take no arguments. in that case, you need parens in order to call them. x = pos.getX() y = pos.getY() return self.room[(x,y)] in self.room a simple print of x and y could have revealed this as well. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor