python AttributeError:'NoneType'对象没有属性'tag'

时间:2015-05-12 15:32:53

标签: python python-2.7

我想要做的是观看带有pyinotify的文件夹以及放入该文件夹的任何mp3 eyed3选择ID3标签(后来添加到数据库中)。这在第一次将文件放入文件夹时完美地工作,但如果我再添加第二个文件,它将崩溃并出现以下错误:

Traceback (most recent call last):
  File "./test.py", line 25, in <module>
    notifier.loop()
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 1424, in loop
    self.process_events()
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 1321, in process_events
    self._default_proc_fun(revent)
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 960, in __call__
    return _ProcessEvent.__call__(self, event)
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 680, in __call__
    return meth(event)
  File "./test.py", line 16, in process_IN_CREATE
    print track.tag.artist
AttributeError: 'NoneType' object has no attribute 'tag'

到目前为止我的代码:

import pyinotify
import eyed3

# The watch manager stores the watches and provides operations on watches
wm = pyinotify.WatchManager()

mask = pyinotify.IN_CREATE  # watched events

class EventHandler(pyinotify.ProcessEvent):
    def process_IN_CREATE(self, event):
        name = event.pathname
        track = eyed3.load(name)
        print track.tag.artist
        print track.tag.title
        print track.tag.album
        print track.info.bit_rate[1]

handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('/home/mark/Desktop/test', mask, rec=True)
notifier.loop()

注意:不是标签为空的情况,无论是第一次跟踪工作还是第二次跟踪工作

0 个答案:

没有答案