Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'none:': 0.07; 'function,': 0.09; 'naturally': 0.09; 'none)': 0.09; 'try:': 0.09; '(possible': 0.16; 'awkward,': 0.16; 'callable': 0.16; 'false)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func': 0.16; 'indexerror:': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'thu,': 0.19; 'example': 0.22; 'print': 0.22; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'list:': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'crash': 0.31; 'maybe': 0.34; 'except': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'useful': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'more': 0.64; 'it"': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+/9HMSw2OvMYBwS+TcpsVtNrnYEKqUOGOK5BY6+Oqu0=; b=hdJC/posEkwlMw8PTuV9kUgtCokg5riZ1M/w5GiH8R4VatRWcN4AKjSUFmo53HSz50 8oFvg4GqHvVjiGd2sKJmTC072ZnuQkvOKuZ86WyUKPwiReOAbNd4LFXNrTJfXNBpmx1I Kqx9g2VFJIxQ30k0GY7inP2oQTQVLVQp6Rh6ZAseYR9ZdocSrpkdNx0svDdZGJY/8DKS ftVL0yxeNzibkGlzc+MtgAVijQdFm2M5sZj/L+i1NAjMxXXrCnVB2wTjSP8xaaNYExod jTB77wf2Rhznu74BYxSUAmMskkfs/qelT5RHxEdv94lVQTgH9R5VX5P8mGFLXDNh0Alp hrxQ== MIME-Version: 1.0 X-Received: by 10.66.164.136 with SMTP id yq8mr13634725pab.67.1381387549620; Wed, 09 Oct 2013 23:45:49 -0700 (PDT) In-Reply-To: References: <91180c35-413f-4b65-a224-917d8d68b7ec@googlegroups.com> Date: Thu, 10 Oct 2013 17:45:49 +1100 Subject: Re: Python's and and Pythons or 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.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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381387558 news.xs4all.nl 16005 [2001:888:2000:d::a6]:49261 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56547 On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi wrote: > I'm trying to think of a good example usage of echo-argument and. Maybe something like > > possible = foo and foo.allowsit() > if (possible is None) : > print "foo not provided" > if (possible is False) : > print "foo doesn't allow it" > > A bit awkward, echo-argument or is more naturally useful to me then echo-argument and. first_element = some_list[0] # Oops, may crash try: first_element = some_list[0] except IndexError: firstelement = None # A bit verbose first_element = some_list and some_list[0] # or if you want a zero instead of an empty list: first_element = len(some_list) and some_list[0] Also, consider the case where you have a function, or None: result = func(*args,**kwargs) # NoneType is not callable result = func and func(*args,**kwargs) ChrisA