python中使用hasattr(x,'call')来判断一个对象是否存在某个方法

class Person:
  def PrintName(self):
    print 'Is a Person'
  def PrintHello(self):
    print 'Hello, world'

per = Person()
per.PrintName()
print hasattr(per,'PrintName')#True

原文地址:https://www.cnblogs.com/Alexander11/p/4156199.html