if __name__ == "__main__"

Thomas Jensen thomasNO at SPAM.obscure.dk
Wed Dec 19 18:56:09 EST 2001


Henrik Motakef <henrik at moskau.hmotakef.homeip.net> wrote in 
news:87lmfyucr4.fsf at moskau.hmotakef.homeip.net:

>>>> import sys
>>>> sys.__name__
> 'sys'
>>>> import sys as foo foo.__name__ 'sys'
> 
> Why isn't foo.__name__ not 'foo', exactly?

The name foo is a reference to the module named 'sys'. Unlike many 
other objects, modules has names. The default behaviour of import is to 
bind the name of the module in the global namespace to the module 
object (or something like that ;-).

-- 
Thomas Jensen



More information about the Python-list mailing list