我試圖使用超()一個簡單的類層次結構以這種方式:使用類超()
class Employee(object):
def __init__(self, name):
self.name = name
class FullTime(Employee):
def __init__(self, name, satOff, freeDays=[], alDays=[], programDays=[]):
global satsOffDict
global dayDict
super(Employee, self).__init__(name)
不過,我得到這個錯誤:
TypeError: object.__init__() takes no parameters
我讀過你需要製作父對象類型對象(新樣式類)以便超級工作。如果我改變Employee類(對象)類Employee(),我得到這個錯誤:
TypeError: must be type, not classobj
這是怎麼回事?
您可能希望小心地將列表作爲默認'__init__'來傳遞。這只是乞求有趣的行爲... http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument – mgilson