Just a quick question about main()
ROGER GRAYDON CHRISTMAN
dvl at psu.edu
Fri Oct 27 14:05:47 EDT 2017
While teaching my introductory course in Python, I occasionally see
submissions containing the following two program lines, even before
I teach about functions and modules:
if __name__ = '__main__':
... main()
When I ask about it, I hear things like they got these from other instructors,
or from other students who learned it from their instructors, or maybe
from some on-line programming tutorial site.
I'm all on board with the first of these two lines -- and I teach it myself
as soon as I get to modules.
My question is more about the second.
Do "real" Pythonista's actually define a new function main() instead
of putting the unit test right there inside the if?
Or am I correct in assuming that this main() is just an artifact from
people who have programmed in C, C++, or Java for so long that
they cannot imagine a program without a function named "main"?
I guess I'm not stuck on that habit, since my programming experiences
go way back to the old Fortran days....
Roger Christman
Pennsylvania State University
More information about the Python-list
mailing list