2010-07-09 66 views

回答

5
>>> import __builtin__ 
>>> builtin_types= [t 
... for t in __builtin__.__dict__.itervalues() 
... if isinstance(t, type)] 

>>> import pprint 
>>> pprint.pprint(sorted(builtin_types, key=repr)) 
[<type 'basestring'>, 
<type 'bool'>, 
<type 'buffer'>, 
<type 'bytearray'>, 
<type 'classmethod'>, 
<type 'complex'>, 
<type 'dict'>, 
<type 'enumerate'>, 
<type 'exceptions.ArithmeticError'>, 
<type 'exceptions.AssertionError'>, 
<type 'exceptions.AttributeError'>, 
<type 'exceptions.BaseException'>, 
<type 'exceptions.BufferError'>, 
<type 'exceptions.BytesWarning'>, 
<type 'exceptions.DeprecationWarning'>, 
<type 'exceptions.EOFError'>, 
<type 'exceptions.EnvironmentError'>, 
<type 'exceptions.Exception'>, 
<type 'exceptions.FloatingPointError'>, 
<type 'exceptions.FutureWarning'>, 
<type 'exceptions.GeneratorExit'>, 
<type 'exceptions.IOError'>, 
<type 'exceptions.ImportError'>, 
<type 'exceptions.ImportWarning'>, 
<type 'exceptions.IndentationError'>, 
<type 'exceptions.IndexError'>, 
<type 'exceptions.KeyError'>, 
<type 'exceptions.KeyboardInterrupt'>, 
<type 'exceptions.LookupError'>, 
<type 'exceptions.MemoryError'>, 
<type 'exceptions.NameError'>, 
<type 'exceptions.NotImplementedError'>, 
<type 'exceptions.OSError'>, 
<type 'exceptions.OverflowError'>, 
<type 'exceptions.PendingDeprecationWarning'>, 
<type 'exceptions.ReferenceError'>, 
<type 'exceptions.RuntimeError'>, 
<type 'exceptions.RuntimeWarning'>, 
<type 'exceptions.StandardError'>, 
<type 'exceptions.StopIteration'>, 
<type 'exceptions.SyntaxError'>, 
<type 'exceptions.SyntaxWarning'>, 
<type 'exceptions.SystemError'>, 
<type 'exceptions.SystemExit'>, 
<type 'exceptions.TabError'>, 
<type 'exceptions.TypeError'>, 
<type 'exceptions.UnboundLocalError'>, 
<type 'exceptions.UnicodeDecodeError'>, 
<type 'exceptions.UnicodeEncodeError'>, 
<type 'exceptions.UnicodeError'>, 
<type 'exceptions.UnicodeTranslateError'>, 
<type 'exceptions.UnicodeWarning'>, 
<type 'exceptions.UserWarning'>, 
<type 'exceptions.ValueError'>, 
<type 'exceptions.Warning'>, 
<type 'exceptions.ZeroDivisionError'>, 
<type 'file'>, 
<type 'float'>, 
<type 'frozenset'>, 
<type 'int'>, 
<type 'list'>, 
<type 'long'>, 
<type 'object'>, 
<type 'property'>, 
<type 'reversed'>, 
<type 'set'>, 
<type 'slice'>, 
<type 'staticmethod'>, 
<type 'str'>, 
<type 'str'>, 
<type 'super'>, 
<type 'tuple'>, 
<type 'type'>, 
<type 'unicode'>, 
<type 'xrange'>] 
1

relational special methods的存在不足以保證可比性;如果方法不喜歡傳遞給它們的特定類型,方法仍然可以引發異常。

+0

謝謝,我已經知道(關於'complex'的例子) - 但我想要的是一種枚舉所有類型的方法,你知道嗎? – 2010-07-09 06:49:47

+0

那麼,你可以從'object .__子類__()'開始,但只能捕獲新風格的類。 – 2010-07-09 06:54:19

相關問題