NameError: name '__main__' is not defined

Sean DiZazzo half.italian at gmail.com
Mon Sep 14 04:29:36 CEST 2009


On Sep 13, 6:43 pm, Peng Yu <pengyu... at gmail.com> wrote:
> Hi,
>
> I try the following code. I don't quite understand why __main__ is not
> defined. Could somebody let me know what I am wrong about it?
>
> Regards,
> Peng
>
> $ cat test.py
> #!/usr/bin/env python
>
> if __main__ == '__main__' :
>   print "Hello World!\n"
> $ ./test.py
> Traceback (most recent call last):
>   File "./test.py", line 3, in <module>
>     if __main__ == '__main__' :
> NameError: name '__main__' is not defined

Is this a production program that you are using??

Please show us the point you are trying to make in something more
valuable.

~Sean



More information about the Python-list mailing list