【发布时间】:2017-04-12 00:57:52
【问题描述】:
我的 IndentationError 似乎无法解决。 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)
【问题讨论】:
-
发布确切的错误 - 它可能包含行号!
-
也将代码贴在错误附近。很可能缩进不当。最后,请在此处发布代码之前将所有制表符替换为 4 个空格。
-
如果正确答案为您解决了问题,您应该将其标记为“已接受”。点击答案旁边的复选标记。
-
您可能指的是一个发布错误消息的人没有任何源代码(Q 肯定被删除了,我现在找不到了)。我认为您很好,但正如其他人所说,包含实际错误消息会使问题更好。
标签: python indentation