Adapted for Python.