Python's equivalent to Main calling program and subprograms
Steve Holden
steve at holdenweb.com
Wed Dec 1 12:38:15 EST 2010
On 12/1/2010 12:08 PM, m b wrote:
>
>
>> >
>> > if __name__ == "__main__":
>> > main()
>
> What does this mean?
>
> /Mikael
>
It's a standard way of allowing programs to test themselves. When a
module is imported its __name__ attribute us bound to the name of the
module. When the module is run as a main program (from the command line)
its __name__ attribute is set to "__main__".
The main() call just calls a function that (presumably) tests the
functions the module provides.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list