[Twisted-Python] what is a non-class class?
Wolfgang Rohdewald
wolfgang.kde at rohdewald.de
Wed Sep 3 01:55:26 MDT 2014
Am Mittwoch, 3. September 2014, 00:29:59 schrieb Glyph:
> > That is my problem. How do I know if the object is of a non-class class?
>
> isinstance(something, (types.ClassType, type)).
but that will make it possible to attach a method even to type "int"
Python2:
>>> isinstance(int, type)
True
> >>> isinstance(object, type)
> True
> >>> isinstance(object(), type)
> False
>
Sure but the test only gets the class and it should certainly not instantiate it.
Meanwhile I believe it is best to simply remove the test since python itself
will reject most:
>>> a=int
>>> a.x=5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'int'
--
Wolfgang
More information about the Twisted-Python
mailing list