Is it possible to create C-style "main" function in Python? (for teaching purposes)
Gregory Ewing
greg.ewing at canterbury.ac.nz
Mon Oct 3 17:50:25 EDT 2011
Ian Kelly wrote:
> I would suggest giving them the whole if __name__ block as boilerplate
> and telling them they're not allowed to alter it.
I would suggest not showing them "if __name__" at all;
instead encourage them to do this:
def main():
...
...
main()
You only need "if __name__ == '__main__'" if you want
a .py file that can be used as either a module or a
main program. Most of the time you *don't* need that.
I consider it advanced usage that beginners shouldn't
be confused with.
--
Greg
More information about the Python-list
mailing list