Empty list as default parameter

Alex Panayotopoulos A.Panayotopoulos at sms.ed.ac.uk
Fri Nov 21 22:29:07 CET 2003

On Fri, 21 Nov 2003, Peter Otten wrote:

> To be consistent you could do
> self.myList = myList[:] or []

TypeError. You can't slice None.
If you're going to be taking copies on entry, you might as well use

	def __init__( self, myList=[] ):
		self.myList = myList[:]

However, copying is inefficient. Not a problem in most cases, but 
I've got a lot of objects to initialise. (This is for a GA). Solution: use 
"myList or []", but carefully.

<<<Alexspudros Potatopoulos>>>
Defender of Spudkind

More information about the Python-list mailing list