2011-07-15 39 views
2

繼承隊列時,我繼承隊列我得到一個錯誤:你如何在Python

super(domainQueue,self).__init__() 
TypeError: must be type, not classobj 

,當我讀了它,東西長約經典類等

如何初始化基隊列類?

回答

2

Queue.Queue是一種舊式的類,因此它不支持新式類的許多功能(如super)。你有兩個選擇,顯式調用Queue.Queue在TorelTwiddler的回答表明,或object添加到基地:

class myQueue(Queue.Queue, object): 
    def __init__(self): 
     super(myQueue, self).__init__() 
1

要簡單地使用它,請改爲使用Queue.__init__(self)

class myQueue(Queue.Queue): 
    def __init__(self): 
     Queue.Queue.__init__(self) 

爲什麼它返回一個classobj而不是type?不知道。

+0

當我使用__init__函數失敗不會有一個初始化函數 –

+0

盡我放在編輯。 – TorelTwiddler