nick34992
1/21/2017 - 8:15 AM

Python Example of main() Module for Initializing a Program

Python Example of main() Module for Initializing a Program

#!/usr/bin/python3
'''
FileName: main_example.py
Author: nick3499
Created: Fri Jan 20 2017
Python Version: 3.5
'''

import turtle

def main():
    t = turtle.Turtle()

if __name__ == "__main__":
    main()

'''
A main() function, like this, initializes a program.

The if statement evaluates to True 
before this module runs as stand-alone.
And `__name__` is `__main__`.

The if statement evaluates to False
when this module is imported into another module with an import statement.
And `__name__` is `main_example`.
'''