python improvements (Was: Re: New Language)
Bernhard Herzog
herzog at online.de
Tue May 16 19:10:47 EDT 2000
emile at fenx.com 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
another:
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 online.de | http://sketch.sourceforge.net/
More information about the Python-list
mailing list