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


Groups > comp.lang.python > #52353

Elegant compare

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jsf80238@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'none,': 0.07; 'attributes': 0.09; 'def': 0.12; '__lt__(self,': 0.16; 'accordingly,': 0.16; 'subject:Elegant': 0.16; 'subject:compare': 0.16; 'message-id:@mail.gmail.com': 0.30; 'long.': 0.31; 'class': 0.32; 'run': 0.32; 'to:name:python-list': 0.33; 'skip:_ 10': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'being': 0.38; 'problems': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'real': 0.63
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=nVG7V/FsEjv+18HyR82ikNO8dkH13CqsZiifnxgBDh4=; b=jKB/H+F04T7zcqrh4eFSxE982GUxFrHmUGsy7ink/G3PHzJjHV3yUtJmHgizGcXE/M QOeK60td4Gkth4HPUfX19cPVTqzqhCYi2s6/fp6MwoH/6bg0cLLw8NIXbSx0a/Sutav1 yxIIo+w8Vu2hYz+i4+ay/ILjksPEDvXg8UcmiedTrhY35x8VZRuNFhApootkwupUpPqM hfhdOvYRLMqp5TMuDWfsnWnP1l/NMHJXjNULd1TFw8nasfOxsi43HsDX+9cEJcryD12R Us/WXMHK73NudC/J7Z5IWzPzvaPeG/7ChQ+Gqefv7mRx92XsCn2YyksdCwozE7HPLJJm 4cCw==
MIME-Version 1.0
X-Received by 10.205.7.6 with SMTP id om6mr2906593bkb.18.1376192460329; Sat, 10 Aug 2013 20:41:00 -0700 (PDT)
Date Sat, 10 Aug 2013 21:41:00 -0600
Subject Elegant compare
From Jason Friedman <jsf80238@gmail.com>
To python-list <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.460.1376192467.1251.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376192467 news.xs4all.nl 15865 [2001:888:2000:d::a6]:54176
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52353

Show key headers only | View raw


class my_class:
    def __init__(self, attr1, attr2):
        self.attr1 = attr1 #string
        self.attr2 = attr2 #string
    def __lt__(self, other):
        if self.attr1 < other.attr1:
            return True
        else:
            return self.attr2 < other.attr2

I will run into problems if attr1 or attr2 is None, and they
legitimately can be.

I know I can check for attr1 or attr2 or both being None and react
accordingly, but my real class has ten attributes and that approach
will be long.  What are my alternatives?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Elegant compare Jason Friedman <jsf80238@gmail.com> - 2013-08-10 21:41 -0600
  Re: Elegant compare Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-11 08:26 +0000
    Re: Elegant compare Jason Friedman <jsf80238@gmail.com> - 2013-08-11 09:17 -0600

csiph-web