8

All I'm looking for is a list of possible values of classinfo since the documentation doesn't provide one and I can't seem to find one anywhere else online, let alone SO.

4
  • Whats your question? Jul 28, 2018 at 1:45
  • Is your question about how to get list of types Jul 28, 2018 at 1:46
  • @U9-Forward nothing to do with lists. my question or request is for a list of classinfo types in the context of isinstance(object, classinfo) for python 3.x
    – oldboy
    Jul 28, 2018 at 1:51
  • What isn't clear about "If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised."? Jul 28, 2018 at 2:23

1 Answer 1

2
print([t for t in __builtins__.__dict__.values() if isinstance(t, type)])

Output (line-breaks inserted for readability):

[
     <class '_frozen_importlib.BuiltinImporter'>,
     <class 'bool'>,
     <class 'memoryview'>,
     <class 'bytearray'>,
     <class 'bytes'>,
     <class 'classmethod'>,
     <class 'complex'>,
     <class 'dict'>,
     <class 'enumerate'>,
     <class 'filter'>,
     <class 'float'>,
     <class 'frozenset'>,
     <class 'property'>,
     <class 'int'>,
     <class 'list'>,
     <class 'map'>,
     <class 'object'>,
     <class 'range'>,
     <class 'reversed'>,
     <class 'set'>,
     <class 'slice'>,
     <class 'staticmethod'>,
     <class 'str'>,
     <class 'super'>,
     <class 'tuple'>,
     <class 'type'>,
     <class 'zip'>,
     <class 'BaseException'>,
     <class 'Exception'>,
     <class 'TypeError'>,
     <class 'StopAsyncIteration'>,
     <class 'StopIteration'>,
     <class 'GeneratorExit'>,
     <class 'SystemExit'>,
     <class 'KeyboardInterrupt'>,
     <class 'ImportError'>,
     <class 'ModuleNotFoundError'>,
     <class 'OSError'>,
     <class 'OSError'>,
     <class 'OSError'>,
     <class 'OSError'>,
     <class 'EOFError'>,
     <class 'RuntimeError'>,
     <class 'RecursionError'>,
     <class 'NotImplementedError'>,
     <class 'NameError'>,
     <class 'UnboundLocalError'>,
     <class 'AttributeError'>,
     <class 'SyntaxError'>,
     <class 'IndentationError'>,
     <class 'TabError'>,
     <class 'LookupError'>,
     <class 'IndexError'>,
     <class 'KeyError'>,
     <class 'ValueError'>,
     <class 'UnicodeError'>,
     <class 'UnicodeEncodeError'>,
     <class 'UnicodeDecodeError'>,
     <class 'UnicodeTranslateError'>,
     <class 'AssertionError'>,
     <class 'ArithmeticError'>,
     <class 'FloatingPointError'>,
     <class 'OverflowError'>,
     <class 'ZeroDivisionError'>,
     <class 'SystemError'>,
     <class 'ReferenceError'>,
     <class 'BufferError'>,
     <class 'MemoryError'>,
     <class 'Warning'>,
     <class 'UserWarning'>,
     <class 'DeprecationWarning'>,
     <class 'PendingDeprecationWarning'>,
     <class 'SyntaxWarning'>,
     <class 'RuntimeWarning'>,
     <class 'FutureWarning'>,
     <class 'ImportWarning'>,
     <class 'UnicodeWarning'>,
     <class 'BytesWarning'>,
     <class 'ResourceWarning'>,
     <class 'ConnectionError'>,
     <class 'BlockingIOError'>,
     <class 'BrokenPipeError'>,
     <class 'ChildProcessError'>,
     <class 'ConnectionAbortedError'>,
     <class 'ConnectionRefusedError'>,
     <class 'ConnectionResetError'>,
     <class 'FileExistsError'>,
     <class 'FileNotFoundError'>,
     <class 'IsADirectoryError'>,
     <class 'NotADirectoryError'>,
     <class 'InterruptedError'>,
     <class 'PermissionError'>,
     <class 'ProcessLookupError'>,
     <class 'TimeoutError'>
 ]

and if you want list of strings:

print([t.__name__ for t in __builtins__.__dict__.values() if isinstance(t, type)])

Output:

[
    'BuiltinImporter',
    'bool',
    'memoryview',
    'bytearray',
    'bytes',
    'classmethod',
    'complex',
    'dict',
    'enumerate',
    'filter',
    'float',
    'frozenset',
    'property',
    'int',
    'list',
    'map',
    'object',
    'range',
    'reversed',
    'set',
    'slice',
    'staticmethod',
    'str',
    'super',
    'tuple',
    'type',
    'zip',
    'BaseException',
    'Exception',
    'TypeError',
    'StopAsyncIteration',
    'StopIteration',
    'GeneratorExit',
    'SystemExit',
    'KeyboardInterrupt',
    'ImportError',
    'ModuleNotFoundError',
    'OSError',
    'OSError',
    'OSError',
    'OSError',
    'EOFError',
    'RuntimeError',
    'RecursionError',
    'NotImplementedError',
    'NameError',
    'UnboundLocalError',
    'AttributeError',
    'SyntaxError',
    'IndentationError',
    'TabError',
    'LookupError',
    'IndexError',
    'KeyError',
    'ValueError',
    'UnicodeError',
    'UnicodeEncodeError',
    'UnicodeDecodeError',
    'UnicodeTranslateError',
    'AssertionError',
    'ArithmeticError',
    'FloatingPointError',
    'OverflowError',
    'ZeroDivisionError',
    'SystemError',
    'ReferenceError',
    'BufferError',
    'MemoryError',
    'Warning',
    'UserWarning',
    'DeprecationWarning',
    'PendingDeprecationWarning',
    'SyntaxWarning',
    'RuntimeWarning',
    'FutureWarning',
    'ImportWarning',
    'UnicodeWarning',
    'BytesWarning',
    'ResourceWarning',
    'ConnectionError',
    'BlockingIOError',
    'BrokenPipeError',
    'ChildProcessError',
    'ConnectionAbortedError',
    'ConnectionRefusedError',
    'ConnectionResetError',
    'FileExistsError',
    'FileNotFoundError',
    'IsADirectoryError',
    'NotADirectoryError',
    'InterruptedError',
    'PermissionError',
    'ProcessLookupError',
    'TimeoutError'
]
7
  • 1
    the reason i ask is because i just swapped my code from a 2.7 environment to a 3.7 enviro and now it's telling me NameError: name 'unicode' is not defined? Any idea what i should be testing for??
    – oldboy
    Jul 28, 2018 at 2:06
  • 3
    @Anthony unicode is now just str. Also, this is not an exhaustive list of either the types that come in Python or the possible types that coudl exist. Jul 28, 2018 at 2:24
  • @juanpa.arrivillaga well, then how do i get a list of all classinfo types for 3.x?! put it as the answer and ill mark it as correct
    – oldboy
    Jul 28, 2018 at 2:53
  • 1
    @Anthony classinfo is the name of a parameter, that accepts either a type object or a tuple of type objects. Since you can create your own types (i.e. classes) then there is no exhaustive list. Jul 28, 2018 at 2:55
  • @juanpa.arrivillaga ohhhhh, i misread that. so then how would one get a list of all the type objects?
    – oldboy
    Jul 28, 2018 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.