Is there a way to get __thismodule__?
benhoyt at gmail.com
Wed Mar 19 19:18:06 CET 2008
Wow -- thanks, guys. And who said Python only gives you one way to do
things. :-) Metaclasses, globals(), and __subclasses__. Thank Duncan
for the __subclassess__ tip -- I didn't know about that.
I'd totally overlooked globals(). It's exactly what I was looking for
-- thanks, Peter. And I like your is_true_subclass() helper function
I must say, I found it a bit weird that the first argument to
issubclass() *has* to be a class. I would have thought issubclass(42,
MyClass) would simply return False, because 42 is definitely not a
subclass of MyClass. But I guess "explicit is better than implicit",
and being implicit here might mask bugs.
globals() feels like the "right" way to do what I want -- fairly
simple and direct. Metaclasses are cool, but probably a touch too
complicated for this. And __subclassess__ seems a bit undocumented and
More information about the Python-list