gpt4 book ai didi

python - 类信息类型列表

转载 作者:太空狗 更新时间:2023-10-30 01:31:22 26 4
gpt4 key购买 nike

我要查找的是自 documentation 以来 classinfo 可能值的列表没有提供,我似乎无法在网上其他任何地方找到,更不用说了。

最佳答案

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

输出(插入换行符以提高可读性):

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

如果你想要字符串列表:

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

关于python - 类信息类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51567356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com