The same file can be run as a program or imported as a module, and sometimes it needs to know which. Python hands every module a variable called __name__ that tells it, and an if on that variable is the idiom you will see at the bottom of nearly every script.
More lessons in Complete Python Programming