Fixed #19211 -- Adapted tutorial for Python 3

Backport of 7cc3acbb7 from master.