Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.059 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'used.': 0.09; '~ethan~': 0.09; 'python': 0.11; 'wrote:': 0.18; 'separate': 0.22; 'header:User- Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'long.': 0.31; 'class': 0.32; 'probably': 0.32; 'url:python': 0.33; "i'd": 0.34; "can't": 0.35; 'agree': 0.35; 'but': 0.35; 'instances': 0.36; 'method': 0.36; 'url:org': 0.36; 'expected': 0.38; 'implement': 0.38; 'filter': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:173': 0.61; 'smith': 0.68; '10:11': 0.84; 'batchelder': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'url:reference': 0.84 Date: Sat, 01 Nov 2014 11:29:03 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: __index__ References: <545510c7$0$27750$862e30e2@ngroups.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414866549 news.xs4all.nl 2919 [2001:888:2000:d::a6]:34945 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80099 On 11/01/2014 10:11 AM, Ned Batchelder wrote: > On 11/1/14 12:56 PM, duncan smith wrote: >> >> I have a Bloom filter class and want to (partially) serialize >> instances using hex() or oct(). Instances are mutable, so I can't >> inherit from long. I thought I'd found the answer when I came across >> __index__, it doesn't seem to work as I expected it to. > > Just above your link in the docs is __oct__ and __hex__, which are used to implement oct() and hex(): > https://docs.python.org/2/reference/datamodel.html#object.__oct__ In Python 2 __oct__ and __hex__ are used for oct() and hex(), but in Python 3 __index__ is used. But I agree with Net that using a separate method is probably better. -- ~Ethan~