Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?
Duncan Booth
duncan.booth at invalid.invalid
Mon May 24 16:12:36 EDT 2010
Terry Reedy <tjreedy at udel.edu> wrote:
> Builtin classes, named or not, do not have dotted names
>
> >>> 1 .__class__
><class 'int'>
> >>> class C: pass
>
> I believe all others do, including C-coded extension classes.
>
> >>> C().__class__
><class '__main__.C'>
>
Not quite all. Classes created by calling the type constructor directly
don't have to follow that rule:
>>> C = type('Fred', (object,), {})
>>> C.__name__
'Fred'
More information about the Python-list
mailing list