better python3 support
rearranged test for PYLAB