[IronPython] Modules importing each other

Michael Foord fuzzyman at voidspace.org.uk
Tue Dec 16 13:19:22 CET 2008


You would find the same thing in CPython. When you execute Program.py it 
is run with the name '__main__' (the main program being executed). When 
you import it, you import it with the name 'Program' which causes it to 
be imported with a different name. I suggest you put your debug symbol 
in a separate module that both Program.py and LogMessage.py import from.

Michael Foord


Yash Ganthe wrote:
> I use IronPython 2.0.
>
> In Program.py I have:
> print "hello"
> DEBUGMODE=0
> .
> .
> .
> import LogMessage
>
> In LogMessage.py I have
> from Program import DEBUGMODE
>
> When I run :
> ipy Program.py
> I observe that "hello" is printed twice: Once when Program.py is run 
> and next when a symbol from Program.py is imported in LogMessage. If 
> one module imports another, does it execute all statements in it even 
> if that module has been loaded before?
> What do I need to do to avoid it?
>
> Program.py and LogMessage.py are both in the same folder.
>
> Thanks,
> Yash
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/




More information about the Ironpython-users mailing list