Python: how to resolve IndentationError

My IndentationError just seems so insoluble. http://pastebin.com/AFdnYcRc .

#!/usr/bin/env python
import os
import glob
import shutil
import mutagen
from sys import exit

musicdir = raw_input("What directory are the music files located in? : ")
musfile = glob.glob(musicdir + '/' + "*.mp3")
musfile1 = glob.glob(musicdir + '/' + "*.flac")
musfile.extend(musfile1)
newmusicdir = raw_input("What directory should the music files be organized into? : ")


done = False

while not done:
    for m in musfile:
        if musfile:
            try:
                musta = mutagen.File(m, easy=True)
                mar = str(musta['artist'][0])
                mal = str(musta['album'][0])
                mti = str(musta['title'][0])
                mtr = str(musta['tracknumber'][0])
                os.makedirs(newmusicdir + '/' + mar + '/' + mal + '/')
            except OSError:
                pass
            finally:
                try:
                    if m.endswith('.mp3'):
                        os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.mp3')
                        m =mtr + ' - ' + mar + ' - ' + mti + '.mp3'
                        shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
                    elif m.endswith('.flac'):
                        os.rename(m,mtr + ' - ' + mar + ' - ' + mti + '.flac')
                        m = mtr + ' - ' + mar + ' - ' + mti + '.flac'
                        shutil.move(m,newmusicdir + '/' + mar + '/' + mal + '/')
        elif not musfile:
                print "Looks like we're done here. Please press <enter> to exit"
                raw_input()
                sys.exit(0)
+3
source share
4 answers

I do not see the block exceptfor the second try. This should break it, but I don’t think it gives you IndendationErrorso that you have more problems.

+5
source

You have a block try(starting at line 30) withoutexcept

+13
source

- pep8 (), .

test.py:12:80: E501 line too long (86 characters)
test.py:18:1: W191 indentation contains tabs
test.py:32:18: E231 missing whitespace after ','
test.py:33:10: E225 missing whitespace around operator
test.py:42:16: W292 no newline at end of file
+5

- . . , . - 4- . vim set ts=4 sw=4 expandtab.

Posting your mistake in your question would make it less likely to be slow, instead of asking people to grab your code and run it on their own ...

As @Mu Mind said, you also have a block trywith no exceptor sentence finally. Since you did not submit your error, I cannot be sure, but I bet if you read it, she will say something in the line "Unexpected indent on line 39 ..." or similar. Either remove this try, or add exception handling.

+2
source

All Articles