Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.04; 'onto': 0.05; 'method,': 0.07; 'bytes,': 0.09; 'foo': 0.09; 'hash': 0.09; 'recursion': 0.09; '>>>': 0.12; 'def': 0.13; 'am,': 0.14; 'skip:f 30': 0.14; 'wrote:': 0.14; 'callable,': 0.16; 'fascinating!': 0.16; 'fascinating.': 0.16; 'foo,': 0.16; 'richardson': 0.16; 'simplicity.': 0.16; 'interesting.': 0.19; 'appear': 0.19; 'not.': 0.22; 'header:In-Reply-To:1': 0.22; 'itself.': 0.22; 'values': 0.23; 'builds': 0.23; 'objects': 0.24; 'compare': 0.26; 'skip:[ 10': 0.26; 'object': 0.27; 'pass': 0.27; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; 'sat,': 0.29; 'elements': 0.29; 'list': 0.30; 'implement': 0.30; 'does': 0.31; 'equal': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'actually': 0.34; 'point': 0.35; 'none': 0.36; 'else': 0.37; 'two': 0.37; 'received:209.85': 0.37; 'apr': 0.38; 'cycle': 0.38; 'other,': 0.38; 'playing': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; 'subject: (': 0.39; 'received:209': 0.39; 'takes': 0.40; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'ever': 0.65; 'subject:The': 0.69; '__call__': 0.84; 'received:209.85.210.174': 0.84; 'received:mail-iy0-f174.google.com': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=oSehiVizJIOiOS4QCr9zkJqDtQys7wYC9OpQ/vE+CHg=; b=fWP5SyjdbGHgXOz+20JtV4bX0Xdg3PHI6hsUqZ7zYDH50l+xfyJ/d2d+cdwlip61gV PXf3pAcBDWrNmEpwcEgVrQ4f8/Trx9a38G75HlajWyohODakLkkgcoer7FiuA+6k9m5l 5wFSEXCYP+rnJZM1jqvdtRx2FORHfWvUqHRWk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=BKMyG4brkFsvYxYUFFf8gOW17z6sxch34V8J3UtAD/iLYIBdtBSPtcmW08yLrVsCvp wB4SLR4RculKmRwG+hGXB3492Zaj1D70oG9fAHhstqc4G8RAB7Sjbz3Y/O6qXbGRGuOH llqhPputAOEpq5QDVPO93r6dXy8357jXDXfN8= MIME-Version: 1.0 In-Reply-To: <4D95EA23.10802@aim.com> References: <4D95EA23.10802@aim.com> Date: Sat, 2 Apr 2011 02:17:54 +1100 Subject: Re: The Magick of __call__ (Or, Digging Deeper Than I Ought To) From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 47 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301671077 news.xs4all.nl 81485 [::ffff:82.94.164.166]:40112 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2362 On Sat, Apr 2, 2011 at 2:07 AM, Corey Richardson wrote: > All callables (things you can foo(bar)) are really just objects that > implement the __call__ method, as far as I understand. Well then, that > would appear to make methods themselves callable, so let's do a little > playing around... Interesting. >>> def Foo(): pass >>> Foo >>> Foo.__call__ >>> Foo.__call__.__call__ >>> Foo.__call__.__call__.__call__ I'd have thought that it would simply use Foo.__call__ == Foo, for simplicity. It's not. >>> a=[Foo] >>> a.append(a[-1].__call__) # repeat above line as many times as desired - builds a list of the recursion >>> a[-1]==a[-2] False So at no point does it ever actually cycle onto itself. >>> import sys >>> [sys.getsizeof(q) for q in a] [60, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32] The function object takes 60 bytes, everything else 32. >>> [q.__hash__() for q in a] [18502128, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592] None of the elements compare equal to each other, but apparently there's only two hash values possible for them! Fascinating. I don't know that it's any use, but fascinating! ChrisA