Basic Class/Instance Question

Alan Franzoni alan.franzoni_invalid at geemail.invalid
Wed May 23 07:19:44 EDT 2007


Il 23 May 2007 04:07:19 -0700, Siah ha scritto:

> Ready to go insane here. Class A, taking on a default value for a

__init__ is a function, taking a default value of [], which is a list,
which is a mutable object. That said, you should remember that this means
that such default value is 'shared' between all instances. If you don't
want that, do something like:

def __init__(self, defaultvalue=None):
	if defaultvalue is None:
		defaultvalue=[]

http://docs.python.org/tut/node6.html#SECTION006710000000000000000


-- 
Alan Franzoni <alan.franzoni.xyz at gmail.com>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 



More information about the Python-list mailing list