aalshabaan
aalshabaan

Reputation: 51

can't find the syntax error in the code

this code is giving a syntax error when interpreted I appreciate the help this code is supposed to return the length of each mp3 file

    import os, sys
from mutagen.mp3 import MP3

USAGE = "python %s <folder here>" %(sys.argv[0])

def get_file_length(path):
    #print "path is " + path
    audio = MP3(path)
    return int(audio.info.length)

def process_folder(folder):
    for item in os.listdir(folder):
        if os.path.isdir(folder+item):
            process_folder(folder+item+"/")
        else:
            if not item.startswith("."):
                path = folder+item
                length = get_file_length(path)
                print"%s\t%d"%(path[19:],length)

if __name__=="__main__":
    if len(sys.argv) < 2:
        print USAGE
    else:
        root = sys.argv[1]
        if not root.endswith("/"):
            root += "/"
        process_folder(root)

the error seems to be in this line

print"%s\t%d"%(path[19:],length)

Upvotes: 0

Views: 175

Answers (1)

Robᵩ
Robᵩ

Reputation: 168716

You are using a Python3 interpreter, but not using the required new syntax for print:

Try this:

print("%s\t%d"%(path[19:],length))

and, later:

print (USAGE)

Upvotes: 2

Related Questions