Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.04; 'problem:': 0.07; 'aliases': 0.09; 'friday,': 0.09; 'satisfy': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '(false,': 0.16; '(true,': 0.16; '23,': 0.16; 'distinct': 0.16; 'entities.': 0.16; 'enum': 0.16; ':-)': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '>>>>': 0.31; 'workaround': 0.31; 'class': 0.32; 'fri,': 0.33; 'skip:_ 10': 0.34; 'something': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'january': 0.37; 'searching': 0.37; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'ian': 0.60; 'tell': 0.60; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=3lbANDqCAzjDQor7ffZol/GTuJQMWPPGmnlinjSVYSs=; b=mJywNKVN2BgRKKaY7un2jMSxPSp0kOFX2uVU7Z3wnRNYZLtHxbx2xKEpg3usV99/Du 7c1oF6uaAs9nBrqyDj/owH0TUKS9CC6XDLyButo/7M8uq+xrUcFGAzpJ2tGnzSp0M9Xf EFk7b7Ns7uIgD+r/r1MgS7mAqNhz1MGVefV5uOHo5S09d3inQbCIaHHcvwmzu4G46j9t Rv/9QMl6kij6Wf3WIhizai5eaMl3ryFQatnBBWFWiNQ7rxk6vusI+lqFLpYOfA1+4K3O VJT805c6Xg8VKWzaik9smm/IFwnkBD518WF0zMNuiULa9ZPr6M0Oog0t8rP7h4CkGCP5 mf3w== X-Received: by 10.68.221.165 with SMTP id qf5mr12966062pbc.101.1422036298782; Fri, 23 Jan 2015 10:04:58 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <5a785a32-3855-457f-be3f-76066dfb20c8@googlegroups.com> References: <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> <54AC97D9.4010504@r3dsolutions.com> <54ACAA04.60801@r3dsolutions.com> <54ADC99F.3020405@stoneleaf.us> <54B44A64.7010105@r3dsolutions.com> <54b4aded$0$2738$c3e8da3$76491128@news.astraweb.com> <54B5B486.7080406@r3dsolutions.com> <54B72D32.3090209@r3dsolutions.com> <54B76B0A.7050706@r3dsolutions.com> <5a785a32-3855-457f-be3f-76066dfb20c8@googlegroups.com> From: Ian Kelly Date: Fri, 23 Jan 2015 11:04:18 -0700 Subject: Re: Comparisons and sorting of a numeric class.... To: Python Content-Type: text/plain; charset=UTF-8 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422036308 news.xs4all.nl 2865 [2001:888:2000:d::a6]:47650 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84377 On Fri, Jan 23, 2015 at 10:03 AM, Rustom Mody wrote: > On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: >> On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: >> > Can you tell me what of the following code does not satisfy your requirements? >> > [Needs python 3.4] >> > >> > >> >>>> from enum import IntEnum >> >>>> class B4(IntEnum): >> > F1 = 0 >> > F2 = 0 >> > F3 = 0 >> > T = 1 >> >> This strikes me as a potential problem: >> >> >>> B4.F1 is B4.F2 is B4.F3 >> True >> >>> list(B4) >> [, ] >> >> Enum members with the same values are just aliases for one another, >> not distinct entities. > > Yeah.... > > The only workaround I have been able to come up with is: > > class B4(IntEnum): >> F1 = 0 >> F2 = "" >> F3 = None >> T = 1 > > which is not bad; its ridiculous > [Like going around with a broken broom searching for falsey objects :-) ] How about something like this: >>> from enum import Enum >>> class B4(Enum): ... F1 = (False, 1) ... F2 = (False, 2) ... F3 = (False, 3) ... T = (True, 4) ... def __bool__(self): ... return self.value[0] ... >>> B4.F1 is B4.F2 False >>> bool(B4.F1) False >>> bool(B4.T) True