Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38439
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Implicit conversion to boolean in if and while statements |
| Date | 2013-02-08 12:11 +0100 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <kf2mgm$a3o$1@r03.glglgl.gl> (permalink) |
| References | (9 earlier) <mailman.2201.1342502395.4697.python-list@python.org> <50050f70$0$30002$c3e8da3$5496439d@news.astraweb.com> <mailman.2203.1342513414.4697.python-list@python.org> <21fcdb92-20e3-428b-b06b-057065a4ab25@oo8g2000pbc.googlegroups.com> <2ab8f33d-d515-4e41-bd1a-1d6e1bc87383@googlegroups.com> |
Am 08.02.2013 07:29 schrieb Rick Johnson:
> Consider this:
>
> if connect("my:db") as db:
> <do something>
>
> No need to make a call and then test for the validity of the call when you can do both simultaneously AND intuitively.
Would be great, but can be emulated with
def ifiter(x):
if x: yield x
for db in ifiter(connect("my:db")):
<do sth with db>
Is not very intuitive, however, but does its job.
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Implicit conversion to boolean in if and while statements Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-07 22:29 -0800 Re: Implicit conversion to boolean in if and while statements Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-02-08 12:11 +0100 Re: Implicit conversion to boolean in if and while statements alex23 <wuwei23@gmail.com> - 2013-02-10 18:38 -0800
csiph-web