Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90125
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.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.025 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'argument': 0.05; 'modify': 0.07; '[],': 0.09; 'function,': 0.09; 'omit': 0.09; 'used.': 0.09; 'cc:addr:python-list': 0.11; 'argument,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'tuple,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'up.': 0.33; 'fri,': 0.33; 'used,': 0.33; 'problem.': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'subject:?': 0.36; 'list': 0.37; 'list.': 0.37; 'pm,': 0.38; 'rather': 0.38; 'help,': 0.39; 'read': 0.60; 'guarantee': 0.63; 'worth': 0.66; 'frank': 0.68; 'frequently': 0.68; 'default': 0.69; 'safe': 0.72; 'subject:this': 0.83; '2015': 0.84; 'safe.': 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=e8/Theshf97ZGhc4uq3BoZxqjgn+MO4dKnK04Tt2OSs=; b=hCouZlRLiNOyg9doNwpbJ6rKNjJRt5Us6l6Cz9v27dDYka5VUTAHnJuRfyBYMtoTGB E0lZFkn8XzVBngcrP8Gh5OuSKjlSDITEgQTz3f/PgPk7vjZq2ADaSQrjKY9kIHZFgQG3 5kd7ryKZDsi7z9XlNUOtvzRMajqAifWjJgm7Gy3IOF3Q5Fu/mHpTgqxJ8Y5DU5RseV+2 DDLiQP++2NoHyVRsFNsVMw5fHsMEP0XGQUk5E/wnDgltUbVnujbjTcatzDOaG8CIpm+p SAFgSEpyohs3hPh0TOSIEOkhsQiFnuw1yrUG5S/GvSc2yKmTm+qvgGtO385ufRxnsgvu bTtw== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.43.199 with SMTP id y7mr2895922ice.12.1431073514628; Fri, 08 May 2015 01:25:14 -0700 (PDT) |
| In-Reply-To | <mihqhb$r1k$1@ger.gmane.org> |
| References | <mihqhb$r1k$1@ger.gmane.org> |
| Date | Fri, 8 May 2015 18:25:14 +1000 |
| Subject | Re: Is this unpythonic? |
| 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.20+ |
| 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.225.1431073517.12865.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431073517 news.xs4all.nl 2844 [2001:888:2000:d::a6]:52642 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:90125 |
Show key headers only | View raw
On Fri, May 8, 2015 at 6:01 PM, Frank Millman <frank@chagford.com> wrote: > I have often read about the gotcha regarding 'mutable default arguments' > that frequently trips people up. > > I use them from time to time, but I have never had a problem. I have just > delved a bit deeper to see if I am skating on thin ice. > > AFAICT my usage is safe. If I use a list as an argument, I only use it to > pass values *into* the function, but I never modify the list. So if I omit > the argument, the original default empty list is used, otherwise the list > that I pass in is used. In that case, you may want to consider using a default of () rather than [], unless there's some reason that it has to be a list. With a tuple, you have a guarantee that it's not going to be changed, so it's as safe as a default argument of True or 42 or "Hello". That may or may not help, but it's worth considering, especially if all you really need is an iterable (or a sequence). ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is this unpythonic? Chris Angelico <rosuav@gmail.com> - 2015-05-08 18:25 +1000
csiph-web