Python 3 fixes for ctool scripts