我有基類,像下面蟒蛇2.7 - 如何調用父類的構造
class FileUtil:
def __init__(self):
self.outFileDir = os.path.join(settings.MEDIA_ROOT,'processed')
if not os.path.exists(outFileDir):
os.makedirs(outFileDir)
## other methods of the class
,我如下擴展該類:
class Myfile(FileUtil):
def __init__(self, extension):
super(Myfile, self).__init__()
self.extension = 'text'
## other methods of class
但我得到下面的錯誤?
super(Myfile, self).__init__()
TypeError: super() takes at least 1 argument (0 given)
我經歷了許多文件,發現在2.x和3.x中調用super()有不同的sytex。我嘗試了兩種方式,但得到錯誤。
的可能的複製[Python中,調用超構造函數(http://stackoverflow.com/questions/2399307/python-invoke-super-constructor) –
我沒有看到你的代碼 – tinySandy
我任何麻煩我在Django中使用這段代碼。雖然我可以理解Django並沒有特定的內容,但仍然在問我是否缺少某些東西。 – virus