[英]Python type annotations for instance of class derived from abstract base class
[英]Is it possible create instance of derived type from instance of base class
像這樣的東西:
class Reference (object):
pass
new_type = type ('{0}_refrence'.format (type (instance).__name__),
(type (instance), Reference), {})
new_instance = new_type (instance)
我想使實例派生自Refrence,但行為與往常一樣...是否可能? 提前謝謝!
如果我明白你想做什么...
class Reference(object): pass
instance = 2
new_type = type('{0}_reference'.format(instance.__class__.__name__), (instance.__class__, Reference), {})
new_instance = new_type(instance)
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.