Return
true if the object argument is an
instance of the classinfo argument, or
of a (direct or indirect) subclass
thereof. Also return true if classinfo
is a type object (new-style class) and
object is an object of that type or of
a (direct or indirect) subclass
thereof. If object is not a class
instance or an object of the given
type, the function always returns
false. If classinfo is neither a class
object nor a type object, it may be a
tuple of class or type objects, or may
recursively contain other such tuples
(other sequence types are not
accepted). If classinfo is not a
class, type, or tuple of classes,
types, and such tuples, a TypeError
exception is raised.
您也可以使用异常处理来执行此操作。
你在找:
不管你想做什么似乎都不是个好主意。请详细描述您最初的需求,我们将帮助您设计出更好的设计。
hasattr(x, 'foo')
是一个内置的二进制函数,用于检查对象x
是否具有属性x.foo
(是否从其类中获取),这似乎与您的要求很接近。你所问的是不是你应该问的是一个不同的问题——正如@Eli的answer所建议的,你的设计看起来很奇怪。不过,这确实回答了你提出的问题。相关问题 更多 >
编程相关推荐