python 3 compatibility

@tfoote Please review.