Possible Duplicate:
How to identiy whether a variable is a class or an object
I have a function which accepts 'things' which it calls.
def run_it(thingy):
result = thingy(something)
However, I'd like run_it()
to accept both classes and objects/functions, and if it is a class, instantiate it first:
def run_it(thingy):
if it_is_a_class:
instance = thingy(something)
result = instance()
else:
result = thingy(something)
class Thingy1(object):
def __init__(self, something):
self.something = something
def __call__(self):
print self.something
class Thingy2(object):
def __call__(self. something):
print something
# First example, call with class:
result = run_it(Thingy1)
# Second example, call with object:
thingy = Thingy2()
result = run_it(thingy)
How do I implement it_is_a_class
in the run_it()
function?