if __name__ == 'main':

Grant Edwards grante at visi.com
Tue Mar 20 18:00:17 CET 2007

On 2007-03-20, gtb <goodTweetieBird at hotmail.com> wrote:

> I often see the following 'if' construct in python code. What does
> this idiom accomplish?

It checks to see if the file is being run as the "main"
program, and does something if that is so.

> What happens if this is not main?


> How did I get here if it is not main?

By importing the file.

> if __name__ == 'main':
>    myQuest('myQuest').Run()

Grant Edwards                   grante             Yow!  Thank god!!... It's
                                  at               HENNY YOUNGMAN!!

More information about the Python-list mailing list