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


Groups > comp.lang.python > #90628

Re: a python pitfall

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'think,': 0.07; 'default.': 0.09; 'warn': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'mutable': 0.16; 'subject:python': 0.16; 'example': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'received:google.com': 0.35; 'list': 0.37; 'being': 0.38; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'believe': 0.68; 'url:me': 0.69; 'obvious': 0.74; 'saw': 0.77
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:to :cc:content-type; bh=Z+dKzUHQXj1idu/gTRwTYpDI6vuKZjymdg6kX19r4RA=; b=s5yOC7xVUTIFEe6S+4Be2BHE80L6uSZOvG+9bCLPnzzRTfPpv57ygL1F1yGZ8+J6gb pIkWQIOUHKbgCwZWkMHATZkZJbazadygYs6eQhkaL547SGwMNXRvwlG+QCodKVuAsogW C6UwgT5B1wJPnShfEp/xf5Hz9yzhcZjIKxE6pUtIvUvaEj1SKG/EBGZxjcqCwPmGcplH vA0vGDdyFUUl4G10FJRM+YvIwFqlTat/90qTixxAUvMFj38e+jMaI6FAx0+0M1w7Z/lq UnjqYY/hJDgLCnrHtvvRc0Uk3SdOu2VRw1pEzvCQfJqIirHuUa9UUPK353jehYw1yZ+e UouQ==
MIME-Version 1.0
X-Received by 10.202.18.203 with SMTP id 194mr4552122ois.110.1431629723377; Thu, 14 May 2015 11:55:23 -0700 (PDT)
In-Reply-To <CAB1ii-cFpbmdjQfRA_J3TBUZ+Gx8e8vLvqTLo2R-f0ygkykV1A@mail.gmail.com>
References <CAB1ii-cFpbmdjQfRA_J3TBUZ+Gx8e8vLvqTLo2R-f0ygkykV1A@mail.gmail.com>
Date Thu, 14 May 2015 13:55:23 -0500
Subject Re: a python pitfall
From Skip Montanaro <skip.montanaro@gmail.com>
To Billy Earney <billy.earney@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.15.1431629731.17265.python-list@python.org> (permalink)
Lines 10
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431629731 news.xs4all.nl 2911 [2001:888:2000:d::a6]:60004
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90628

Show key headers only | View raw


> I saw the following example at
> http://nafiulis.me/potential-pythonic-pitfalls.html#using-mutable-default-arguments
> and did not believe the output produced and had to try it for myself....

Pylint (and perhaps other Python "linters") would, I think, warn you
that you were using a mutable object as a default. It's more obvious
that the list is being reused if you call foo with different values
each time.

Skip

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


Thread

Re: a python pitfall Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-14 13:55 -0500

csiph-web