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


Groups > comp.lang.python > #90152

Re: Is this unpythonic?

Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.039
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'argument': 0.05; 'modify': 0.07; "(i'd": 0.09; 'promising': 0.09; 'def': 0.12; 'wrote': 0.14; 'gotcha.': 0.16; 'skip:n 50': 0.16; 'thereby': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'code,': 0.22; 'header:User-Agent:1': 0.23; 'tend': 0.24; 'looks': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'fri,': 0.33; 'but': 0.35; 'subject:?': 0.36; 'wrong': 0.37; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'charset:windows-1252': 0.65; 'frank': 0.68; 'nobody': 0.68; 'received:74.208': 0.68; 'default': 0.69; 'subject:this': 0.83; '2015': 0.84; 'acceptable)': 0.84; 'trick,': 0.84
Date Fri, 08 May 2015 08:04:34 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Is this unpythonic?
References <mailman.224.1431072121.12865.python-list@python.org> <554c8b0a$0$12992$c3e8da3$5496439d@news.astraweb.com> <mii4il$vv$1@ger.gmane.org>
In-Reply-To <mii4il$vv$1@ger.gmane.org>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V03:K0:/+gC4kCQz1pPegbxsNWJS1XfmKqYmXQiDzvR1NgFAdqJAXcsXFp qNzmcC1C2y0nx81i/qDQzQ3jPiuU7ohMyM6fB8dxfbXPkaiWgY8XtaAdB63mv2OhKZ254eO hdLcWRNir9vdav56+LtJiskVtEac7mWFqGmam1940SueqBB9esgM57XGwWtSUJBnItTGds9 XlTp4XzwXH3wEx8hFdhFg==
X-UI-Out-Filterresults notjunk:1;
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.239.1431086688.12865.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431086688 news.xs4all.nl 2830 [2001:888:2000:d::a6]:45584
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90152

Show key headers only | View raw


On 05/08/2015 06:53 AM, Frank Millman wrote:
>
> "Steven D'Aprano" <steve+comp.lang.python@pearwood.info> wrote in message
> news:554c8b0a$0$12992$c3e8da3$5496439d@news.astraweb.com...
>> On Fri, 8 May 2015 06:01 pm, Frank Millman wrote:
>>
>>> Hi all
>>>
> [...]
>>>
>>> However, every time I look at my own code, and I see   "def x(y, z=[]):
>>> ....."   it looks wrong because I have been conditioned to think of it as
>>> a gotcha.
>>

It might be appropriate to define the list at top-level, as

EMPTY_LIST=[]

and in your default argument as
     def x(y, z=EMPTY_LIST):

and with the all-caps, you're thereby promising that nobody will modify 
that list.

(I'd tend to do the None trick, but I think this alternative would be 
acceptable)

-- 
DaveA

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


Thread

Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 10:01 +0200
  Re: Is this unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-08 20:08 +1000
    Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 12:53 +0200
      Re: Is this unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 01:07 +1000
        Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 07:56 +0200
        Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 08:51 +0200
          Re: Is this unpythonic? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 19:47 +1200
            Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 11:10 +0200
    Re: Is this unpythonic? Dave Angel <davea@davea.name> - 2015-05-08 08:04 -0400
      Re: Is this unpythonic? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-05-10 10:04 +0200
        Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-10 10:58 +0200
          Re: Is this unpythonic? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-05-10 11:54 +0200
            Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-10 12:40 +0200
    Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 15:12 +0200

csiph-web