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


Groups > comp.lang.python > #20046 > unrolled thread

Re: Id of methods

Started byTerry Reedy <tjreedy@udel.edu>
First post2012-02-08 23:08 -0500
Last post2012-02-08 23:08 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#20046 — Re: Id of methods

FromTerry Reedy <tjreedy@udel.edu>
Date2012-02-08 23:08 -0500
SubjectRe: Id of methods
Message-ID<mailman.5562.1328760552.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web