Why would I use inspect.isclass()?
It's me
itsme at yahoo.com
Wed Dec 29 20:27:11 EST 2004
I discovered the hardway what inspect.isclass() is doing. Consider this no
brainer code:
###
import inspect
class Abc:
def Hello(self):
return
an_instance=Abc()
print inspect.isclass(an_instance)
###
It took me a while to understand how I can get inspect.isclass to return a
True (like: inspect.isclass(Abc)).
But what good is that? Of course I know Abc is a class, why would I want to
inspect it so that it would tell me what I already know?
I would have thought this would be the situation I need that for:
###
import inspect
class Abc:
def Hello(self, some_class):
# since I don't know if the argument passed down *is* a class or not, I
would:
if inspect.isclass(some_class)==True:
...
return
###
But that obviously isn't what isclass is for. What should I use?
Thanks,
More information about the Python-list
mailing list