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


Groups > comp.lang.python > #90211

Re: Is this unpythonic?

Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'list?': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'assume': 0.14; 'wrote': 0.14; "wouldn't": 0.14; "chris'": 0.16; 'dictionaries': 0.16; 'dictionary,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:n 50': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'unlike': 0.19; '>>>': 0.22; 'instead.': 0.24; 'sorry,': 0.24; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'idea': 0.28; 'work.': 0.31; 'probably': 0.32; 'worked': 0.33; 'fri,': 0.33; 'could': 0.34; 'but': 0.35; 'subject:?': 0.36; 'should': 0.36; 'changing': 0.37; 'list.': 0.37; 'work?': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'decided': 0.64; 'more': 0.64; 'situation': 0.65; 'here': 0.66; 'frank': 0.68; 'default': 0.69; 'subject:this': 0.83; '2015': 0.84; 'trick,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Is this unpythonic?
Date Sat, 9 May 2015 07:56:54 +0200
References <mailman.224.1431072121.12865.python-list@python.org> <554c8b0a$0$12992$c3e8da3$5496439d@news.astraweb.com> <mailman.231.1431082398.12865.python-list@python.org> <554cd119$0$12977$c3e8da3$5496439d@news.astraweb.com>
X-Gmane-NNTP-Posting-Host 197.89.68.193
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.3790.4657
X-MimeOLE Produced By Microsoft MimeOLE V6.00.3790.4913
X-RFC2646 Format=Flowed; Original
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.270.1431151023.12865.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431151023 news.xs4all.nl 2870 [2001:888:2000:d::a6]:56091
X-Complaints-To abuse@xs4all.nl
X-Received-Body-CRC 1512953109
X-Received-Bytes 4058
Xref csiph.com comp.lang.python:90211

Show key headers only | View raw


"Steven D'Aprano" <steve+comp.lang.python@pearwood.info> wrote in message 
news:554cd119$0$12977$c3e8da3$5496439d@news.astraweb.com...
> On Fri, 8 May 2015 08:53 pm, Frank Millman wrote:
>
>>> Does z have to be a list? Could you use an empty tuple instead?
>>>
>>> def x(y, z=()): ...
>>>
>>
>> That was Chris' suggestion as well (thanks Chris).
>>
>> The idea appealed to me, but then I found a situation where I pass in a
>> dictionary instead of a list, so that would not work.
>
>
> Why wouldn't it work? If it worked with an empty list, it will probably 
> work
> with an empty tuple instead.
>

Sorry, I should have been more explicit. In the case of a dictionary, I used 
'def x(y, z={}'

I have not checked, but I assume that as dictionaries are mutable, this 
suffers from the same drawback as a default list.

Unlike a list, it cannot be replaced by an empty tuple without changing the 
body of the function.

Dave's suggestion would have worked here -

    EMPTY_LIST = []
    EMPTY_DICT = {}

But as I have decided to use the None trick, I use it for a default 
dictionary as well.

Frank




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