Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69434
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'python,': 0.02; 'else:': 0.03; 'elif': 0.05; 'assignment': 0.07; 'subject:query': 0.07; 'lines.': 0.09; 'sake': 0.09; 'url:github': 0.09; 'cc:addr:python- list': 0.11; 'skip:= 70': 0.12; '0.1)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'partly': 0.16; 'unpacking': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'any,': 0.19; '(the': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'subject:Code': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'nearly': 0.26; 'this:': 0.26; 'second': 0.26; 'subject:/': 0.26; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'mode': 0.30; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'went': 0.31; 'code': 0.31; 'context,': 0.31; 'another': 0.32; "i'd": 0.34; 'received:google.com': 0.35; 'version': 0.36; 'done': 0.36; 'question,': 0.38; 'ago,': 0.61; 'break': 0.61; 'reaching': 0.61; 'full': 0.61; 'simple': 0.61; 'here:': 0.62; "you've": 0.63; 'teaching': 0.64; 'more': 0.64; 'vehicle': 0.68; 'meters': 0.84; 'url:master': 0.84; 'to:none': 0.92 |
| 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:cc :content-type; bh=XCdpM9HiiyUqxXm19tySGwvmxmVZtowxoU1kfjqrxA0=; b=YGZaz+F2ZzIPXlQLAwsNcjWVYj+JOA5eQPd5vXzVIFjIlZ8GY3tB3fPd1t++AxSaYE AyW/hvdzm7QiNGkYqXSQmbH7iTuCC8EW9WuA/uRXKk5q1sNTVnPhwCnQFosuolCWARD4 LZileU0aYcifDmKvQOi92lHnbOyiuYnlEoUHUbQb8tzciHyg4pNl72zUWKD71ZOvaUA7 CVebn4mq8aVuDq7WHv6VVoQO3GPzLy3SGrEkLW80ZX6LzkWyENUJ0trxDrGHmIL0iPH5 JGjHqXDi/GQvCsoy5o4BMtoebxVzGO5weVoEHOHJTzWUJBPMhqgfuKYx/33l4lUkje4Q LnHg== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.248.7 with SMTP id yi7mr26179796pbc.31.1396281834852; Mon, 31 Mar 2014 09:03:54 -0700 (PDT) |
| In-Reply-To | <874n2ecr5x.fsf@elektro.pacujo.net> |
| References | <mailman.8744.1396276875.18130.python-list@python.org> <874n2ecr5x.fsf@elektro.pacujo.net> |
| Date | Tue, 1 Apr 2014 03:03:54 +1100 |
| Subject | Re: Code style query: multiple assignments in if/elif tree |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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 | <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.8745.1396281843.18130.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1396281843 news.xs4all.nl 2949 [2001:888:2000:d::a6]:58730 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:69434 |
Show key headers only | View raw
On Tue, Apr 1, 2014 at 2:40 AM, Marko Rauhamaa <marko@pacujo.net> wrote: > As a simple layout question, I'd do it like this: > > ======================================================================== > if mode == "Brake2": > # Already got the brakes fully on > distance_to_full_braking_power = 0.0 > speed_full_brake = curspeed > elif mode == "Brake1": > # The brakes went on one second ago, they're nearly full > distance_to_full_braking_power = curspeed - 0.2125 > speed_full_brake = curspeed - 0.425 > else: > # Brakes aren't on. > distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125) > speed_full_brake = curspeed - 0.625 > > # If we hit the brakes now (or already have hit them), we'll go another > # d meters and be going at s m/s before reaching full braking power. > ======================================================================== No particular advantage over the current version - it doesn't simplify it any, all you've done is break it across more lines. (The unpacking may not be ideal; as I said, this was a vehicle for teaching oddments of Python, so I used multiple assignment partly for the sake of using it.) Incidentally, if you want to see the code in context, it's here: https://github.com/Rosuav/runningtime/blob/master/runningtime.py ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 01:33 +1100
Re: Code style query: multiple assignments in if/elif tree Marko Rauhamaa <marko@pacujo.net> - 2014-03-31 18:40 +0300
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:03 +1100
Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 09:20 -0700
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:29 +1100
Re: Code style query: multiple assignments in if/elif tree "Rhodri James" <rhodri@wildebst.org.uk> - 2014-03-31 21:31 +0100
Re: Code style query: multiple assignments in if/elif tree Ned Batchelder <ned@nedbatchelder.com> - 2014-03-31 17:42 -0400
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 09:50 +1100
Re: Code style query: multiple assignments in if/elif tree Ben Finney <ben+python@benfinney.id.au> - 2014-04-01 09:57 +1100
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 10:12 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-01 00:57 +0000
Re: Code style query: multiple assignments in if/elif tree Ethan Furman <ethan@stoneleaf.us> - 2014-03-31 17:30 -0700
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 04:26 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 16:01 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:20 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:35 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 08:07 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:12 +1100
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:18 -0600
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:24 -0600
Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 22:45 -0700
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:05 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:28 -0600
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:13 -0600
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:24 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:39 -0600
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 17:55 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:29 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:49 +1100
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:29 -0600
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:56 +1100
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:21 -0400
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:26 +1100
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:34 -0400
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:39 -0400
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:46 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:55 -0600
csiph-web