[Tutor] What is `if __name__ == "__main__"` for?

spawgi at gmail.com spawgi at gmail.com
Fri May 20 13:34:15 CEST 2011


If the module is run as a program, then the __name__ is assigned the value
__main__ .
If the module is imported, then the value is not assigned.

Please see here -
http://stackoverflow.com/questions/419163/what-does-if-name-main-do

<http://stackoverflow.com/questions/419163/what-does-if-name-main-do>
On Fri, May 20, 2011 at 4:39 PM, Ganesh Kumar <bugcy013 at gmail.com> wrote:

> Hi Gurus,
>
> I am new python programming.. I see many programs
> if __name__ == '__main__':
>  when I check __name__ always eq __main__.
> what purpose use these structure.. please guide me..
>
> -Ganesh
>
> --
> Did I learn something today? If not, I wasted it.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
http://spawgi.wordpress.com
We can do it and do it better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110520/adef1276/attachment.html>


More information about the Tutor mailing list