Skip to content Skip to sidebar Skip to footer

Usage Of Issubclass

>>> import sys >>> sys.version_info (2, 4, 4, 'final', 0) >>> class C: ... pass ... >>> issubclass(C, C) True >>> issubclass(C, obje

Solution 1:

Take a look at issubclass(class, classinfo) documentation

Return true if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError exception is raised.

and to check base class of C use inspect.getmro(cls) function.

Return a tuple of class cls’s base classes, including cls, in method resolution order.

   >>> class C(object):
...pass...>>>inspect.getmro(C)
(<class '__main__.C'>, <type 'object'>)
>>>

Solution 2:

http://docs.python.org/library/functions.html#issubclass From that link, "A class is considered a subclass of itself."

To answer your second question, C is an "old style" class so it isn't a subclass of object. Include object as the superclass if you want a new style class. See http://www.python.org/doc/newstyle/ for more info.

Solution 3:

http://docs.python.org/library/functions.html#issubclass

  1. A class is considered a subclass of itself.

  2. C has no base class

    print C.__bases__

    ()

Post a Comment for "Usage Of Issubclass"