Python Error Init of Class
下面是我的代码。它给了我一个编译错误,说艺术家还没有定义。这让我很困惑,因为艺术家是我传递的参数。
谢谢。
1 2 3 4 5 6 7 8 9 10 11 | class Track: def __init__(self, artist, title, album=None): self.artist = str(artist) self.title = str(title) self.album = album def __str__(self): return self.artist +"" + self.title +"" + self.album def set_album(self, album): self.album = album |
班级相册:def init(self,artist,title,year='',style='',tracks=none):self.artist=str(艺术家)self.title=str(标题)self.year=str(年)self.tyle=str(流派)self.tracks=曲目
1 2 3 4 5 | def __str__(self): return self.artist +"" + self.title +"" + self.year +"" + self.genre +"" + self.tracks def add_track(track): self.tracks.append(track) |
号
def音乐库(曲目、专辑):
1 2 3 4 5 6 7 8 9 10 11 | while true: command = raw_input("Please enter a command (s, st or sa)").lower() if"s" in command: searchText = command.split()(1) elif"sa" in command: searchText = command.split()(1) elif"st" in command: searchText = command.split()(1) |
导入操作系统从mutagen.mp3导入mp3def加载库(dir):
1 2 3 4 5 6 7 8 9 10 11 12 | for root, dirs, files in os.walk("."): for filename in files: if filename.lower().endswith(".mp3"): fullname = os.path.join(root, filename) print" %s" % fullname try: audio = MP3(fullname) for key in audio: print" %s: %s" % (key, str(audio[key])) except: print"Error on %s" % fullname |
。
这是整个文件。我用的是
python音乐库.py
我怀疑是因为你把标签和空格混在一起了。当我复制粘贴您的代码并查看它时,我看到:
1 2 3 4 5 6 7 8 9 10 11 | ' class Track:' ' \tdef __init__(self, artist, title, album=None):' ' \t\tself.artist = str(artist)' ' self.title = str(title)' ' self.album = album' ' ' ' \tdef __str__(self):' ' \t\treturn self.artist +"" + self.title +"" + self.album' ' ' ' \tdef set_album(self, album):' ' \t\tself.album = album' |
混合制表符和空格会混淆python代码缩进的程度。切换到使用四个空格进行缩进,并使用