python 3 compatibility

@tfoote @wjwwood Please review.