Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107750
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Pythonic style |
| Date | Thu, 28 Apr 2016 13:56:05 +1000 |
| Lines | 20 |
| Message-ID | <mailman.168.1461815768.32212.python-list@python.org> (permalink) |
| References | <5720357B.4060009@icloud.com> <CALwzidn0SN5yax3bfmTPDTxBvfr+bnVNzeUe3dZYrS9ji2WCtw@mail.gmail.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> <CAPTjJmrkELf4rb+1UgmPwHxmd+wzp6WLxxN+ut4L3xJuHhmqmA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de yRxL02UWI9PHV+SfhUFJOQZdKGBnyjuVBFf4sMgIS4Ag== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.025 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'methods,': 0.09; 'thu,': 0.15; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'trying': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; '~ethan~': 0.29; 'classes': 0.30; 'skip:s 30': 0.31; 'maybe': 0.33; 'point': 0.33; 'rule': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'your': 0.60; 'special': 0.73; 'chrisa': 0.84; 'to:none': 0.91; 'ethan': 0.91; 'furman': 0.91 |
| 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; bh=83kwRynn+cN12KUQUwREIyf/15SDHVn/oFXpU6HE4r4=; b=PagJTORtGZR9EIw3KTJ7LrkBrKUwgdxJnAVt5UVyySRRO+1NORFu7s824q5X92VzXm 9RsWZhIUmW8X6quk7wWDyEgUK8NF6XwVJ6ym1koydHZQw7DWnLKpvQJckt5WoXZEcPmN 2hdMswQJDqvkJy8272700y3n4uNeA0dF4hIc8etM8eIyMzPFhUDGFKGunqscYesz+8ZI /MWqc0KQ8YvXXcTHjLUIkako6Y3Zi1MXbM8oVXslouPKeq4nBZEFeEYzmduxsE1eO3i4 hJi8UBBT3qU+32+GAuR+HC5lM7+e7oYHqzxZ5l47i/ISsDQfQFevQZA0N+DaPbdeXz1x NEng== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=83kwRynn+cN12KUQUwREIyf/15SDHVn/oFXpU6HE4r4=; b=HguOO9NJx0QmoQIa/RwlwGyEeJX8mvKMG7GC/NrpTlmLVBwA7aACsq8tDPIoBTMyIv uLsx+BIo8eWGRzuJNTIGB0KYhI2uY7/D5IQVlbjdPmaNyVEVVlUhnLGs59m9kzbDzcNN bHy1eyzjg5Z5z2T34gAAoy9sYaVub2f5TyS5QKCIuji/BTPjZBFNz9fm2wtnbkzX3u3n EVoJuz3d2SkYbtJgGeJvEE+iinX/Ac62/QVmeZdXViVtfJTk2KxRo2Ki653s5PN5f7SJ dnrHzaKaullwHqeDK/noR/4NtSpQiBja7/eFOFQcdmo1f41aZDi0++TMLe9Ph3H6cjnx 7ABA== |
| X-Gm-Message-State | AOPr4FU6mo361cvv2cpybvzTVbDqKMe5jATE4UNvmyS/lKhlo2Qojpluw65jYN88d6naXZgD9reN1ZU/iBdtpA== |
| X-Received | by 10.107.137.166 with SMTP id t38mr14888105ioi.31.1461815765251; Wed, 27 Apr 2016 20:56:05 -0700 (PDT) |
| In-Reply-To | <572188F8.7010304@stoneleaf.us> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <CAPTjJmrkELf4rb+1UgmPwHxmd+wzp6WLxxN+ut4L3xJuHhmqmA@mail.gmail.com> |
| X-Mailman-Original-References | <5720357B.4060009@icloud.com> <CALwzidn0SN5yax3bfmTPDTxBvfr+bnVNzeUe3dZYrS9ji2WCtw@mail.gmail.com> <572166FA.3020108@icloud.com> <85y47yjxj5.fsf_-_@benfinney.id.au> <57217E73.9040907@icloud.com> <572188F8.7010304@stoneleaf.us> |
| Xref | csiph.com comp.lang.python:107750 |
Show key headers only | View raw
On Thu, Apr 28, 2016 at 1:52 PM, Ethan Furman <ethan@stoneleaf.us> wrote: > > The point Ben was trying to make is this: you should never* call __dunder__ > methods in normal code; there is no need to do so: > > - use len(), not __len__() > - use next(), not __next__() > - use some_instance.an_attribute, not some_instance.__dict__['an_attribute'] > > -- > ~Ethan~ > > * Okay, maybe /almost/ never. About the only time you need to is when > giving your classes special methods, such as __add__ or __repr__. My rule of thumb is: Dunders are for defining, not for calling. It's not a hard-and-fast rule, but it'll get you through 99%+ of situations. ChrisA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Pythonic style Chris Angelico <rosuav@gmail.com> - 2016-04-28 13:56 +1000
Re: Pythonic style Rustom Mody <rustompmody@gmail.com> - 2016-04-27 22:16 -0700
Re: Pythonic style MRAB <python@mrabarnett.plus.com> - 2016-04-28 12:16 +0100
Dunder docs again (was Pythonic style) Rustom Mody <rustompmody@gmail.com> - 2016-04-28 04:45 -0700
Re: Dunder docs again (was Pythonic style) MRAB <python@mrabarnett.plus.com> - 2016-04-28 13:02 +0100
Re: Dunder docs again (was Pythonic style) Marko Rauhamaa <marko@pacujo.net> - 2016-04-28 15:25 +0300
Re: Dunder docs again (was Pythonic style) MRAB <python@mrabarnett.plus.com> - 2016-04-28 14:22 +0100
Re: Pythonic style Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-29 12:48 +1200
Re: Pythonic style Chris Angelico <rosuav@gmail.com> - 2016-04-29 10:57 +1000
Re: Pythonic style Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-29 18:12 +1200
Re: Pythonic style Chris Angelico <rosuav@gmail.com> - 2016-04-29 16:45 +1000
Re: Pythonic style Steven D'Aprano <steve@pearwood.info> - 2016-04-29 19:59 +1000
Re: Pythonic style Random832 <random832@fastmail.com> - 2016-04-28 09:31 -0400
csiph-web