Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

This is my code, I am getting a compile-time error:

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

class 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 = 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(tracks, albums):

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)

import os from mutagen.mp3 import 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

That is my file. I am running it using python musiclib.py

1 Answer

0 votes
by (36.8k points)

I think it's because you're going wrong with space and tabs. When I copy and paste your code it looks like this:

'    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'

Kindly check the indentation and run the code in python -tt yourprogramname.py to confirm this diagnosis.

If you are a beginner and want to know more about Data Science the do check out the Data Science course

Related questions

Browse Categories

...