Added try/except for python3 compatibility.

`xrange` is not available in python3 and has been replaced by `range`