Improved code style

Fixed some errors and warning according to the style checker `flake8`:

- E126 continuation line over-indented for hanging indent
- E231 missing whitespace after `:`
- E251 unexpected spaces around keyword / parameter equals
- E261 at least two spaces before inline comment
- E301 expected 1 blank line
- E711 comparison to None should be `if cond is not None:`
- E712 comparison to False should be `if cond is False:` or `if not cond:`
- W391 blank line at end of file
- W601 `.has_key()` is deprecated, use `in`