apply python 3.x support

Original code seems not support python 3.

So, I'd try to apply python 3 support and fix some pep8 violations in this PR.