Unicode literals that work in python 3 and 2

Viewed 10770

So I have a python script that I'd prefer worked on python 3.2 and 2.7 just for convenience.

Is there a way to have unicode literals that work in both? E.g.

#coding: utf-8
whatever = 'שלום'

The above code would require a unicode string in python 2.x (u'') and in python 3.x that little u causes a syntax error.

2 Answers

In 3.0, 3.1, and 3.2:

from __future__ import unicode_literals

Source: ubershmekel, in the question. See revision 4 for the original.

Related