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
- 上一篇 »PHP判断是否都是中文
- 下一篇 »python类装饰器即__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