Classic vs New-style classes...

Jp Calderone exarkun at
Sat Jun 21 00:51:27 CEST 2003

On Fri, Jun 20, 2003 at 05:17:25PM -0500, Martin Chilvers wrote:
> I've searched the archives and docs for an answer to this one, but I'm
> still stuck...
> >>> class Foo(object)
> ...	pass
> ...
> >>> Foo.__dict__['bar'] = lambda self, x: x * 2
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: object does not support item assignment
> >>> type(Foo.__dict__)
> <type 'dict-proxy'>
> Any ideas?

    class Foo(object): pass = lambda self, x: x * 2
    print Foo().bar(10)


In the days when Sussman was a novice Minsky once came to him as he sat
hacking at the PDP-6. "What are you doing?" asked Minsky. "I am training a
randomly wired neural net to play Tic-Tac-Toe." "Why is the net wired
randomly?" asked Minsky. "I do not want it to have any preconceptions of how
to play." Minsky shut his eyes. "Why do you close your eyes?" Sussman asked
his teacher. "So the room will be empty." At that moment, Sussman was

More information about the Python-list mailing list