0
玩弄繼承,並遇到一個錯誤,指出我輸入了太多的參數。我可能做錯了什麼?對象繼承arugment輸入錯誤
第一個文件叫做media.py
class Video():
def __init__(self, title, duration):
self.title = title
self.duration = duration
class Movie(Video):
def __init__(self, movie_story, movie_poster, trailer_youtube):
Video.__init__(self, title, duration)
self.storyline = movie_story
self.poster_image_url = movie_poster
self.trailer_youtube_url = trailer_youtube
def show_trailer(self):
webbrowser.open(self.trailer_youtube_url)
class TvShow(Video):
def __init__(self, season, episode, tv_station):
Video.__init__(self, title, duration)
self.season = season
self.episode = episode
self.tv_station = tv_station
這第二個文件創建的對象。
import fresh_tomatoes
import media
family_guy = media.TvShow("Family Guy",
"2000-Present",
"Fifteen Seasons",
"Twenty-Eight",
"Fox")
print family_guy.title
終端輸出狀態我傳遞6個參數時,只有4可能被接受。這是爲什麼?
你看過你傳遞的參數並將它們與你定義的構造函數進行比較嗎? – user2357112
@ user2357112很好,因爲視頻被TvShow繼承,不應該按照參數的順序:標題,持續時間,季節,劇集,tv_station? – JCD
否。重寫的構造函數不會自動繼承重寫表單的參數。 – user2357112