2012-06-11 42 views
0

添加到一個類的功能。例如的一行代碼在python

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

這是基類..我不能編輯。所以我需要繼承這個類,並且需要在test1()中添加一行list(set(list_of_ids))。我怎樣才能做到這一點?

+2

和你有什麼問題呢?你嘗試了什麼,發生了什麼以及你期望會發生什麼? –

+2

你必須更加精確。問題是什麼?你爲什麼不添加該行? –

+1

你在交互式口譯員中做這個嗎? –

回答

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))