Is this unpythonic?
Dave Angel
davea at davea.name
Fri May 8 08:04:34 EDT 2015
On 05/08/2015 06:53 AM, Frank Millman wrote:
>
> "Steven D'Aprano" <steve+comp.lang.python at pearwood.info> wrote in message
> news:554c8b0a$0$12992$c3e8da3$5496439d at 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
More information about the Python-list
mailing list