小编Tom*_*mas的帖子

如何将(继承)父级转换为子级?

我想知道如何将由某个函数返回的父对象转换为子类.

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类,但由于代码结构不可能.谢谢

python inheritance class

4
推荐指数
3
解决办法
1万
查看次数

标签 统计

class ×1

inheritance ×1

python ×1