Re: NameError: name '__main__' is not defined

2009-09-14 Thread Hendrik van Rooyen
On Monday 14 September 2009 03:43:19 Peng Yu 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

You are looking for __name__ , not __main__

if __name__ == '__main__':
We are at the top of the tree so run something
print Goodbye Cruel World

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NameError: name '__main__' is not defined

2009-09-14 Thread Andre Engels
On Mon, Sep 14, 2009 at 4:29 AM, Sean DiZazzo half.ital...@gmail.com wrote:

 Is this a production program that you are using??

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

I find this a very bad comment. Not only is it rude, it is condemning
a behaviour I would see as beneficial. I very much prefer someone
creating a toy program that is as short and simple as possible while
still showing their problem than being forced through hundreds of
lines of code which contain very useful code which however has nothing
to do with the problem at hand.


-- 
André Engels, andreeng...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


NameError: name '__main__' is not defined

2009-09-13 Thread Peng Yu
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


Re: NameError: name '__main__' is not defined

2009-09-13 Thread Xavier Ho
Try

if __name__ == '__main__'

:],
Xav


On Mon, Sep 14, 2009 at 11:43 AM, Peng Yu pengyu...@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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NameError: name '__main__' is not defined

2009-09-13 Thread André
On Sep 13, 10:43 pm, Peng Yu pengyu...@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

You wrote __main__ instead of __name__.  It should have been:

if __name__ == '__main__':
 ...

André
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NameError: name '__main__' is not defined

2009-09-13 Thread Sean DiZazzo
On Sep 13, 6:43 pm, Peng Yu pengyu...@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
-- 
http://mail.python.org/mailman/listinfo/python-list