有些事情是这样的:
class Reference (object):
pass
new_type = type ('{0}_refrence'.format (type (instance).__name__),
(type (instance), Reference), {})
new_instance = new_type (instance)
我想让实例从Refrence派生,但表现得像往常一样...... 可能吗? Thx提前!
答案 0 :(得分:0)
如果我明白你想做什么......
class Reference(object): pass
instance = 2
new_type = type('{0}_reference'.format(instance.__class__.__name__), (instance.__class__, Reference), {})
new_instance = new_type(instance)
希望这有帮助。