class instance customization

Alexander b3nder at yandex.ru
Sat Apr 17 05:09:43 EDT 2010


Hi, list.

I've some nontrivial class implementation MyClass and its instance my:

my = MyClass(args)

MyClass uses in internals some variable which is not defined in MyClass
itself. I want to extend instance of MyClass at runtime defining this
variable and making new instance. It is like a class inheritance in a
static way

class MyNewClass(MyClass):
    def __init__(s, a):
        s._variable = a

but this doesn't give me ability to make inheritance at runtime of the
single parent intance. Finaly this should look like this

my = MyClass(args)

a1 = my.new(1)
a2 = my.new(2)

and e.t.c. Is it possible to release this interface in python?





More information about the Python-list mailing list