I have a script where I do some magic stuff to dynamically load a module, and instantiate the first class found in the module. But I can't use types.ClassType
anymore in Python 3. What is the correct way to do this now?
views:
312answers:
2
+3
A:
it was used for classic classes, in python3 they're gone.
I suppose you could use: issubclass(ClassName, object)
for example or whatever your class derives from
SilentGhost
2009-02-09 18:30:35
+2
A:
I figured it out. It seems that classes are of type "type". Here is an example of how to distinguish between classes and other objects at runtime.
>>> class C: pass
...
>>> type(C)
<class 'type'>
>>> isinstance(C, type)
True
>>> isinstance('string', type)
False
Christian Oudard
2009-02-09 18:38:20