-1

下面是我的代码。它给了我一个编译错误,说尚未定义艺术家。这让我很困惑,因为艺术家是我传递的参数。

谢谢。

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='',genre='',tracks=None):self.artist = str(artist) self.title = str(title) self.year = str(year ) self.genre = str(genre) self.tracks = 曲目

def __str__(self):
    return self.artist + " " + self.title + " " + self.year + " " + self.genre + " " + self.tracks

def add_track(track):
    self.tracks.append(track)

def music_library(曲目,专辑):

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 导入 o​​s 导入 MP3 def load_library(dir):

for root, dirs, files in os.walk("."):
    for filename in files:
        if filename.lower().endswith(".mp3"):
            fullname = os.path.join(root, filename)
            print "\n%s" % fullname
            try:
                audio = MP3(fullname)
                for key in audio:
                    print "  %s: %s" % (key, str(audio[key]))
            except:
                print "Error on %s" % fullname

那是整个文件。我正在使用它运行它

蟒蛇音乐库.py

4

1 回答 1

3

我怀疑这是因为你混合了制表符和空格。当我复制并粘贴您的代码并查看它时,我看到:

'    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 对代码缩进的程度感到困惑。切换到使用四个空格进行缩进,并运行您的代码python -tt yourprogramname.py以确认此诊断。

于 2013-10-01T15:35:22.880 回答