I have a problem where type comparisons don't work in a second module when unit tests in the first module are run. In the example below, class Test is declared in one.py. When one.py is executed, it calls a method in two.py that imports Test from one.py. The problem is that the Test object passed into the run method is in the "__main__" namespace, while the Test class imported from one.py is in the "one" namespace. Comparing type(a) and Test returns False, even though they are both Test objects. How can I tweak these modules so that the type comparison returns True?
I suppose one solution is to redesign my solution to not compare types, but I would still appreciate a solution for my personal knowledge. **** one.py **** class Test(object): pass if __name__ == '__main__': import two two.run( Test() ) **** two.py *** *def run( a ): from one import Test print type(a), Test, type(a) == Test * *** Output *** *<class '__main__.Test'> <class 'one.Test'> False
-- http://mail.python.org/mailman/listinfo/python-list