Is there a way to get __thismodule__?
benhoyt
benhoyt at gmail.com
Wed Mar 19 14:18:06 EDT 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
too.
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
perhaps implementation-defined.
Cheers,
Ben.
More information about the Python-list
mailing list