在python中向一个类的函数添加一行代码

时间:2012-06-11 10:04:03

标签: python python-2.7

例如

class abcd(base_class):
    def test1(self,list_of_ids):
        ###some other statements
        return list_of_ids

这是基类..我无法编辑。所以我需要继承该类,并需要在test1()中添加一行list(set(list_of_ids))。我怎么能这样做?

1 个答案:

答案 0 :(得分:4)

如果我正确理解你的问题,创建一个子类,调用父类的方法,并修改输出:

class Modifiedabcd(abcd):
    def test1(self, list_of_ids):
        ###some other statements
        temp = super(Modifiedabcd, self).test1(list_of_ids)
        return list(set(temp))