Cleanup and EOF checking

Cleaned up some Python Issues
such as:
- using spaces for indent instead of tabs,
- changed the filename to a .py, instead of .sh
Also:
- added check for EOF in case you are piping input from STDIN
- changed the looping boolean logic to be more clear

The refactoring from @rwjs#2 looks good too, but could be overlaid on top of this one.