OK Figured it out.
You basically need to create a module and import the module, that way it stays permanently in the python environment without being forgotten as soon as the script runs and sets up the UI. It's fine if you don't have UI and are just running a one off script.
This got me to reading up on modules in python, and took me to the next level of creating a full on complex project that I work on through Eclipse and Pydev. http://www.creativecrash.com/tutorials/using-eclipse-as-a-maya-ide/page3#tabs
Lots of other plugins work this way as well. This explains why when adding a python plugin to your shelf, the code that goes into the button is typically:
import mainPluginModuleGoesHere
mainPluginModuleGoesHere.main()
and main is the entry point that sets up all the UI, but it can be called anything besides main, like run, go, etc...