NameError: name '__main__' is not defined

Xavier Ho contact at xavierho.com
Sun Sep 13 22:25:29 EDT 2009


Try

if __name__ == '__main__'

:],
Xav


On Mon, Sep 14, 2009 at 11:43 AM, Peng Yu <pengyu.ut 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090914/1d61737f/attachment.html>


More information about the Python-list mailing list