>>> getattr(list, '__module__')
'__builtin__'
>>>
Yes, it's a good idea, for the most basic types. In fact the question is ambiguous. Types defined in C extension modules are not detected with this method. For example
>>> from collections import deque
>>> print(deque.__module__)
collections
but in fact the deque type lives in a C library
_collections.so . I don't know how to detect this automatically.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Offline 2,656 posts
since Jul 2008