[Tutor] The IF statement

Toby Holland the.tobmeister at gmail.com
Wed Sep 5 23:28:10 CEST 2007

Hi gang,

Just doing what I can to understand as I study

I have been reading about testing modules this is the statement that I have
been given

if __name__ == "__main__":

I understand that all modules have a built in attribute __name__, but what
does the __main__ have to do with this attribute.  Is it saying that
__name__ is the same as __main__?

I know that if the module is imported then __name__is the moules file name,
but is this just for the script that your writing while using that module or
is it just to show that the module was imported?

correct me if I'm wrong please, the modules file name is __main__ when its
being used as a stand alone program?

If this is the case the difference is whether or not the module is a program
by itself or intigrated with a script that is what determines its name (i.e.
__name__ and __main__)

I hope this question makes senses

thanks for the help!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070905/f3a8e0b2/attachment-0001.htm 

More information about the Tutor mailing list