Le Thursday 04 September 2008 22:26:53 Ruediger, vous avez écrit : > Hello! >
Hello, > Executing following little program gives me an TypeError. > > What makes me wonder is that foo does get an argument passed while bar > doesn't. Can anyone explain why?????? > Because id is a builtin written in the core language and doesn't subscribe to the descritpor protocol python functions has. > > class foo(list): > __hash__ = lambda x: id(x) > Wow ! You are really going on trouble with this, believe me there is a real good reason for list not to be hashable. A dictionnary or set containing some of your foo is virtually inconsistent, read carefully the manual about prerequesites for dict keys, they *need* to be immutable. > class bar(list): > __hash__ = id > > _s_ = set() > _s_.add(foo()) > _s_.add(bar()) > > [EMAIL PROTECTED]:~> python test01.py > Traceback (most recent call last): > File "test01.py", line 9, in <module> > _s_.add(bar()) > TypeError: id() takes exactly one argument (0 given) > > -- > http://mail.python.org/mailman/listinfo/python-list -- _____________ Maric Michaud _____________ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 4 26 88 00 97 Mobile: +33 6 32 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list