[Python-Dev] unexpected import behaviour

Oleg Broytman phd at phd.pp.ru
Thu Jul 29 14:53:26 CEST 2010


Hello.

   We are sorry but we cannot help you. This mailing list is to work on
developing Python (adding new features to Python itself and fixing bugs);
if you're having problems learning, understanding or using Python, please
find another forum. Probably python-list/comp.lang.python mailing list/news
group is the best place; there are Python developers who participate in it;
you may get a faster, and probably more complete, answer there. See
http://www.python.org/community/ for other lists/news groups/fora. Thank
you for understanding.

On Thu, Jul 29, 2010 at 07:32:28AM +0100, Daniel Waterworth wrote:
> class Test:
>     pass
> 
> def test_1():
>     import test
>     print Test == test.Test
> 
> if __name__ == '__main__':
>     test_1()
> 
> and then run it ($ python test.py), it'll print False.

   The problem is that when you run the code as a script it is imported as
module __main__; when you import it as 'test' you get the second copy of
the module.

Oleg.
-- 
     Oleg Broytman            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-Dev mailing list