只有函数调用才能通过,但函数仍然有效吗?

时间:2014-07-09 21:02:22

标签: python

嗨!

我目前正在查看位于此处的专辑美术发现者的python代码:
https://github.com/skyostil/albumart 当我查看代码时,我会被一组方法的功能所困扰。

我正在查看的文件是/lib/albumart/albumart.py

Module,Source,Target和Recognizer类是我被卡住的部分。对于这些类中的每一个,它们的方法都接受参数,但是在类中完成的所有操作都是通过的。但是,根据评论,方法做了些什么?有人可以确切地解释一下有什么用吗?

以下是代码的摘录。

class Target(Module):
  #A virtual base class that defines an album cover target
  def gPassetCover(self, path):
    #Returns a cover image for the given path or None if one isn't found
    pass
  def setCover(self, path, cover):
    #Assigns a cover image to the given path. Note that the path may also point to a file
    pass
  def removeCover(path):
    #Removes the album image for the given path. Note that the path may also point to a file
    pass
  def hasCover(self, path):
    #Returns 1 if the given path has an associated cover image and 0 otherwise.
    return 0

2 个答案:

答案 0 :(得分:2)

看起来这个类是为了提供具体的功能(即它是一种abstract type),从“虚拟基类”来判断。

Target的方法本身无效(passNOP)。

答案 1 :(得分:1)

不,来自官方的python docs:

https://docs.python.org/2/tutorial/controlflow.html#pass-statements

  

pass语句什么都不做。它可以在语句中使用   语法要求,但程序不需要采取任何行动。