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


Groups > comp.lang.python > #96160

Re: Python handles globals badly.

References (1 earlier) <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <msapn9$5aa$1@ger.gmane.org> <mailman.205.1441702743.8327.python-list@python.org> <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-09-08 23:08 -0600
Subject Re: Python handles globals badly.
Newsgroups comp.lang.python
Message-ID <mailman.248.1441775353.8327.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Sep 8, 2015 at 9:27 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> Using if...then statement is too heavyweight, and cannot be used in an
> expression. Using "flag and true_value or false_value" is buggy -- it fails
> if true_value is itself false. Refactoring it to a function uses eager
> rather than lazy evaluation. So there was no existing alternative to a
> ternary if expression that worked correctly.

I used to see "(flag and [true_value] or [false_value])[0]" fairly
often, which solves the bugginess problem by ensuring that the second
term can't be false. Not that I would recommend it over an actual
conditional expression.

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


Thread

Re: Python handles globals badly. tdev@freenet.de - 2015-09-03 12:05 -0700
  Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-03 13:47 -0600
  Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-03 13:51 -0600
  Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-03 23:13 +0100
  Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-03 16:45 -0600
  Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2015-09-03 18:06 -0600
  Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-04 01:47 +0100
  Re: Python handles globals badly. Steven D'Aprano <steve@pearwood.info> - 2015-09-04 12:27 +1000
  Re: Python handles globals badly. Steven D'Aprano <steve@pearwood.info> - 2015-09-04 12:33 +1000
    Re: Python handles globals badly. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-08 11:07 +0200
  Re: Python handles globals badly. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-08 10:59 +0200
    Re: Python handles globals badly. Steven D'Aprano <steve@pearwood.info> - 2015-09-09 13:27 +1000
      Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-08 23:08 -0600
      Re: Python handles globals badly. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-09 17:04 +0200
      Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-09 17:46 +0100
  Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-08 10:22 +0100
  Re: Python handles globals badly. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-08 11:59 +0200
  Re: Python handles globals badly. Laura Creighton <lac@openend.se> - 2015-09-08 12:07 +0200

csiph-web