python improvements (Was: Re: New Language)

Bernhard Herzog herzog at
Wed May 17 01:10:47 CEST 2000

emile at writes:

> It looks like you can sneak your way into a class:
> class Pass:
>   None
> class Test:
>   def __init__(self, a,b,c,d,e):
>     self.f = f(a,b,c,d,e)
>   def func(self, a):
>     print "This is a class function (call ref: %s)" % a
> a = Pass()
> a.__class__ = Test
> a.func('class')

Heh, that's a sneaky way to instantiate a class without actually
instantiating it.

Why didn't I think of this, considering that I once seriously considered
using a sort of mind-swap to let one object assume the identity of

        c.__dict__, d.__dict__ = d.__dict__, c.__dict__
        c.__class__, d.__class__ = d.__class__, c.__class__

Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at  |

More information about the Python-list mailing list