Consider you have two python files as defined below. Say one is a general package (class2
), and the other one does specific overrides and serves as the executable (class1
).
class1.py:
#!/usr/bin/python
class Test(object):
pass
class Verificator():
def check(self, myObject):
if not isinstance( myObject, Test ):
print "%s is no instance of %s" % (type(myObject),Test)
else:
print "OK!"
if __name__ == '__main__':
from class2 import getTest
v = Verificator()
t = Test()
v.check(t)
s = getTest()
v.check(s)
class2.py:
from class1 import Test
def getTest():
return Test()
What happens is that the first check is OK, where the second fails. The reason is that t
is __main__.Test
whereas s
is class1.Test
and v.check()
checks for __main__.Test
, but at the end of the day it is the same class, right?
Is there a way to write v.check()
such that it also accepts class1.Test
objects, or any other way to solve this?