replaced function that only works with Python 2.7+