Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56547
| 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 | <rosuav@gmail.com> |
| 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 | <a471eecd-2e9f-4d32-8825-bdc088a0ecb0@googlegroups.com> |
| References | <91180c35-413f-4b65-a224-917d8d68b7ec@googlegroups.com> <a471eecd-2e9f-4d32-8825-bdc088a0ecb0@googlegroups.com> |
| Date | Thu, 10 Oct 2013 17:45:49 +1100 |
| Subject | Re: Python's and and Pythons or |
| From | Chris Angelico <rosuav@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.925.1381387558.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi
<peter.cacioppi@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 16:54 -0700
Re: Python's and and Pythons or Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-10 00:36 +0000
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 12:13 +1100
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:12 -0700
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 17:45 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-09 23:46 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 03:43 -0400
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 19:03 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 06:33 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 21:41 -0400
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 19:47 -0700
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:55 -0700
csiph-web