小编wko*_*son的帖子

检查文件扩展名

我正在处理某个程序,如果有问题的文件是flac文件或mp3文件,我需要让它做不同的事情.我可以用这个吗?

if m == *.mp3
   ...
elif m == *.flac
   ...
Run Code Online (Sandbox Code Playgroud)

我不确定它是否会起作用.

编辑: 当我使用它时,它告诉我无效的语法.那我该怎么办?

python file-extension

138
推荐指数
8
解决办法
21万
查看次数

Python:如何解决IndentationError

我的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]) …
Run Code Online (Sandbox Code Playgroud)

python indentation

3
推荐指数
3
解决办法
1335
查看次数

Python:如何从这种类型的列表中访问数据?

快速Python问题:如何从嵌套列表中访问数据,如下所示:

{'album': [u'Rumours'], 'comment': [u'Track 3'], 'artist': [u'Fleetwood Mac'], 'title': [u'Never Going Back Again'], 'date': [u'1977'], 'genre': [u'Rock'], 'tracknumber': [u'03']}

我试过listname[0][0]但它返回错误: AttributeError: 'int' object has no attribute 'lower'

那我该怎么做呢?

python nested list

2
推荐指数
1
解决办法
1030
查看次数

标签 统计

python ×3

file-extension ×1

indentation ×1

list ×1

nested ×1