[Tutor] conditional execution
Patti Scott
pscott_74 at yahoo.com
Wed Apr 2 17:37:56 CEST 2014
Thank you Emile, Zach, Chris and d.
.... I am actually catching lots of my typos before I try to run anything ...
________________________________
From: spir <denis.spir at gmail.com>
To: tutor at python.org
Sent: Wednesday, April 2, 2014 3:18 AM
Subject: Re: [Tutor] conditional execution
On 04/01/2014 06:24 PM, Zachary Ware wrote:
> Hi Patti,
>
> On Tue, Apr 1, 2014 at 11:07 AM, Patti Scott <pscott_74 at yahoo.com> wrote:
>> I've been cheating: comment out the conditional statement and adjust the
>> indents. But, how do I make my program run with if __name__ == 'main':
>> main() at the end? I thought I understood the idea to run a module called
>> directly but not a module imported. My program isn't running, though.
>
> The simple fix to get you going is to change your ``if __name__ ==
> 'main':`` statement to ``if __name__ == '__main__':`` (add two
> underscores on each side of "main"). To debug this for yourself, try
> putting ``print(__name__)`` right before your ``if __name__ ...``
> line, and see what is printed when you run it in different ways.
>
> Hope this helps, and if you need any more help or a more in-depth
> explanation of what's going on, please don't hesitate to ask :)
And you don't even need this idiom if your module is only to be executed (not
imported). Just write "main()".
d
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140402/34205bc4/attachment.html>
More information about the Tutor
mailing list