[Tutor] How to extract a float from an instancemethod call
Yaniv Bronheim
ybronhei at redhat.com
Mon Apr 15 09:01:37 CEST 2013
by reading the exception you see that you pass function pointer instead of a value
"KeyError: (<bound method Position.getX of <__main__.Position object at
0x4699490>>, <bound method Position.getY of <__main__.Position object at
0x4699490>>)"
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" <s.shall at virginmedia.com>
> To: "Dave Angel" <davea at davea.name>
> 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 <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
> >
> > 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list