Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90152
| Date | 2015-05-08 08:04 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.239.1431086688.12865.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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