Hello Mike, The reason of the problem is that the class Test was not pushed into the sys.modules. Use one more separate module for that stuff: *one.py* class Test(object): '''just define'''
*three.py* from one import Test #push one.pyc to sys.modules if __name__ == '__main__': import two two.run( Test() ) *two.py* def run( a ): from one import Test #reuse existing Test print type(a), Test, type(a) == Test Regards, Alexey On Sat, Aug 2, 2008 at 5:16 PM, Mike Wyatt <[EMAIL PROTECTED]> wrote: > 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 >
-- http://mail.python.org/mailman/listinfo/python-list