On 05/08/2015 06:53 AM, Frank Millman wrote:

"Steven D'Aprano" <steve+comp.lang.pyt...@pearwood.info> wrote in message
news:554c8b0a$0$12992$c3e8da3$54964...@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
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to