Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'function,': 0.07; 'python': 0.08; 'oh,': 0.09; 'received:209.85.214.174': 0.13; 'method.': 0.15; '3.2,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hex': 0.16; 'hint:': 0.16; 'relied': 0.16; 'unbound': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'seems': 0.20; 'trying': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; "shouldn't": 0.23; 'windows': 0.26; 'function': 0.27; 'tried': 0.27; 'beyond': 0.28; 'message-id:@mail.gmail.com': 0.29; 'anyway.': 0.29; 'example': 0.29; "skip:' 10": 0.29; 'print': 0.29; 'seem': 0.29; 'pm,': 0.29; 'none,': 0.30; 'objects.': 0.30; 'thu,': 0.32; 'actual': 0.32; 'object': 0.33; 'anything': 0.34; 'to:addr:python-list': 0.35; 'received:209.85.214': 0.36; 'question': 0.36; 'two': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'difference': 0.38; 'received:209.85': 0.38; 'could': 0.38; 'skip:\xa0 10': 0.39; 'received:209': 0.39; 'being': 0.40; 'might': 0.40; 'to:addr:python.org': 0.40; 'more': 0.61; 'your': 0.61; 'special': 0.66; 'exact': 0.68; 'anything.': 0.71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=pfbspSXj1fzQNoqSy1gRK+0SOvT9btf18h2J8fKI7Sw=; b=JrrD0UcI7zgqrjeinpUhv00I/yMu+j3dyLfn1Ss1AUG40nMbXucjpRU47COo/0U249 65xZrXGqYrC5PpoGbF0DQFAtzQdY0NX+vE/VZ3zOKF9H/Kl2nhWWu/9rQt4liW/4zXPy pLeMSz4GMH1YXzdEnC7Rqm4rB8ecF2u2RqK+c= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 9 Feb 2012 15:06:21 +1100 Subject: Re: Id of methods From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328760384 news.xs4all.nl 6937 [2001:888:2000:d::a6]:49773 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20045 On Thu, Feb 9, 2012 at 2:48 PM, Emeka wrote: > I am trying to see if I could get more of Python without being insane. Oh, I thought insanity was a prerequisite... anyway. > print Boo.__dict__ > > {'__module__': '__main__', 'ball': , 'daf': > , '__dict__ ......} > > print =A0hex(id(Boo.daf)) > 0x27de5a0 > > My question is why is it that the id of Boo.daf =A0is different from daf'= s hex > value in the above dict? Take no notice of the exact value of id(). It is an opaque value that shouldn't be relied upon for anything. That said, though, I tried your example in my two Windows Pythons, 2.6.5 and 3.2; in 3.2, the behavior is most like what you seem to be accepting: >>> Boo.__dict__ dict_proxy({'__module__': '__main__', 'ball': , 'daf': , '__dict__': , '__weakref__': , '__doc__': None, '__init__': }) >>> hex(id(Boo.daf)) '0xfcbc90' >>> Boo.daf Same number everywhere. But 2.6.5 has a difference that might give you a hi= nt: >>> print Boo.__dict__ {'__module__': '__main__', 'ball': , 'daf': , '__dict__': , '__weakref__': , '__doc__': None, '__init__': } >>> Boo.daf daf is not a function, it's a special object for an unbound method. The exact identity of it is not necessarily useful; and buried inside it is the actual function that you defined: >>> hex(id(Boo.daf)) '0x11b5c10' >>> hex(id(Boo.daf.im_func)) '0x11bdc30' And that seems to be the number that's given in the repr(). But mainly, don't rely on id() for anything beyond uniqueness against all current objects. ChrisA