Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20046

Re: Id of methods

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Id of methods
Date 2012-02-08 23:08 -0500
References <CAOypoo4V+KjSxieUM3jU1UO==2nDHuRyzk0Byi8rf3L3YG37eg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5562.1328760552.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 2/8/2012 10:48 PM, Emeka wrote:

>class Boo(object):
>
>      def __init__(self , moon, sun):
>          self.moon = moon
> self.sun = sun
>      def daf(self):
>          return self.sun + self.moon
>      def ball(self):
>          return self.sun * self.moon
>
>
> print Boo.__dict__
>
> {'__module__': '__main__', 'ball': <function ball at 0x286e9b0>, 'daf':
> <function daf at 0x286e938>, '__dict__ ......}
>
> print  hex(id(Boo.daf))
> 0x27de5a0

> My question is why is it that the id of Boo.daf  is different from daf's
> hex value in the above dict?

Because you are using Python 2. Just print Boo.daf and you will see that 
it is not a 'function'. In Python 3, it will be, and have the same address.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Id of methods Terry Reedy <tjreedy@udel.edu> - 2012-02-08 23:08 -0500

csiph-web