fixed typo, adjusted file handling

`open` is preferred over `file`:
http://docs.python.org/2/library/functions.html#file
moved existence check for efficiency and readability
fixed PEP8 compliance

plus minor stylistic adjustments