我想知道如何将由某个函数返回的父对象转换为子类.
class A(object):
def __init__():
pass
class B(A):
def functionIneed():
pass
i = module.getObject()# i will get object that is class A
j = B(i)# this will return exception
j.functionIneed()
Run Code Online (Sandbox Code Playgroud)
我无法改变A类.如果可以的话,我会将classIneed实现到A类,但由于代码结构不可能.谢谢