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

2011-05-20 Thread Ganesh Kumar
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. ___

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

2011-05-20 Thread Walter Prins
On 20 May 2011 12:09, Ganesh Kumar bugcy...@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 Here you go:

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

2011-05-20 Thread spawgi
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

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

2011-05-20 Thread Christian Witts
On 2011/05/20 01:09 PM, Ganesh Kumar 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 If you execute the script directly ie. python script.py

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

2011-05-20 Thread Christian Witts
On 2011/05/20 01:29 PM, Christian Witts wrote: On 2011/05/20 01:09 PM, Ganesh Kumar 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 If you

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

2011-05-20 Thread Hilton Fernandes
Hi, Ganesh ! An important use of this feature is the so-called modular testing, aka unit testing. I mean: that way you can provide functionality in your module to test it independently of any application it may be contained in. Unit testing in general is easier and quicker to do than to test the

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

2011-05-20 Thread Hilton Garcia Fernandes
Hi, Ganesh ! Adding to what Christian already stated, i'd like to tell you that an important use of this feature is the so-called modular testing, aka unit testing. I mean: that way you can provide functionality in your module to test it independently of any application it may be contained in.