[Tutor] Need help with a couple of concepts
Jason Stokes
jstok@bluedog.apana.org.au
Sat, 4 Mar 2000 13:51:41 +1100
Gerrit Holl <gerrit@nl.linux.org>
><quote name="Robin B. Lake" date="952089204" email="rbl@hal.cwru.edu">
>> Long-time programming. Understand most of the Python *language*.
>> Need help with some of the constructs to get a Python program going.
>>
>> Running Python on a Mac G3.
>>
>> 1. Am modifying some code. There is at the bottom:
>>
>> if __name__ == '__main__':
>> main()
>>
>> and after the imports:
>>
>> def main():
>>
>> What is this all about?
>
>If a Python program is run as a script, the value of the __name__
>variable is set to '__main__'; this is not executed if the program
>is imported as a Python module.
The purpose of this is to allow the same module to be used as a library, and
as an application with its own top level. This is useful, for example, to
give library modules their own test routines defined inside the module.