本文介绍了classinfo类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要查找的是 classinfo 的可能值列表,因为文档没有提供文档,而且我似乎无法在网上找到其他任何文档,更不用说了.

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.

推荐答案

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)])

输出:

[
    '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'
]

这篇关于classinfo类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 14:54