[Tutor] How to extract a float from an instancemethod call

Flynn, Stephen (L & P - IT) Steve.Flynn at capita.co.uk
Mon Apr 8 14:48:17 CEST 2013


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 <module>
>      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: (<bound method Position.getX of <__main__.Position object at
> 0x4699490>>, <bound method Position.getY of <__main__.Position object
at
> 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.


More information about the Tutor mailing list