[Tutor] PyScripter header?
Amit Saha
amitsaha.in at gmail.com
Wed May 8 10:14:31 CEST 2013
On Wed, May 8, 2013 at 6:10 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
> I'm trying PyScripter instead of Wing 101. It works fine and has a lot
> more PyLearner features than Wing 101 (at the same price ;'), such as
> popups showing the parameters for methods, profiler, lint,
> programmable snippets, etc. It also lets you choose your Python
> version and finds the right one, which is handy, since I'm learning on
> 3.3 but a lot of good stuff is older.
>
> However, a new file in PyScripter always starts with:
> _____________________________________________
>
> def main():
> pass
>
> if __name__ == '__main__':
> main()
> _____________________________________________
This allows you to write your program in such a way that main() is
called only when you are running it as a standalone script.
If you import your program in another program, the condition: if
__name__=='__main__' evaluates to False and hence your main()
function is not called.
If you had written your program like this:
def main():
pass
main()
Your main() function would be called in both cases.
Some good answers here [1].
[1] http://stackoverflow.com/questions/419163/what-does-if-name-main-do
>
> What is that stuff? I thought I was getting away from all this
> business of defining a main entry point. I don't see it in any of the
> Py library files or other Py programs.
Yes, it just a case of you defining the entry point..you are not required to.
HTH,
Amit.
--
http://echorand.me
More information about the Tutor
mailing list