944,111 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 632
  • Python RSS
Oct 21st, 2009
0

Testing if an object's type is builtin

Expand Post »
Does anyone know how I can test if an object's type is a builtin type or a user defined type ?
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,656 posts
since Jul 2008
Oct 21st, 2009
1
Re: Testing if an object's type is builtin
Does anyone know how I can test if an object's type is a builtin type or a user defined type ?
If it's not builtin, it must be imported from another module.
Python Syntax (Toggle Plain Text)
  1. >>> getattr(list, '__module__')
  2. '__builtin__'
  3. >>>
Reputation Points: 86
Solved Threads: 40
Junior Poster
solsteel is offline Offline
141 posts
since Mar 2007
Oct 22nd, 2009
0
Re: Testing if an object's type is builtin
Click to Expand / Collapse  Quote originally posted by solsteel ...
Python Syntax (Toggle Plain Text)
  1. >>> getattr(list, '__module__')
  2. '__builtin__'
  3. >>>
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
python Syntax (Toggle Plain Text)
  1. >>> from collections import deque
  2. >>> print(deque.__module__)
  3. 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
Gribouillis is offline Offline
2,656 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Faster "single stepping"
Next Thread in Python Forum Timeline: Helping users using object oriented design and code.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC