python 3 compatibility

@wjwwood Please review.