nltk.python_2_unicode_compatible()

nltk.python_2_unicode_compatible(klass)[source]

This decorator defines __unicode__ method and fixes __repr__ and __str__ methods under Python 2.

To support Python 2 and 3 with a single code base, define __str__ and __repr__ methods returning unicode text and apply this decorator to the class.

Original __repr__ and __str__ would be available as unicode_repr and __unicode__ (under both Python 2 and Python 3).