How to make Python 2.x Unicode strings not print as u'string'?

Viewed 7927

I'm currently testing a webservice that returns large amounts of JSON data in the form of dictionaries. The keys and values for those dictionaries are all unicode strings, and thus they print like

{u'key1':u'value', u'key2':u'value2'}

when printed to the screen in the interactive interpreter.

Now imagine that this is a 3-level deep, 40-element dictionary. All those u characters clutter up the display, making it hard to figure out, at a glance, what the real data actually is. Even when using pprint.

Is there any way to tell the interpreter that I don't care about the difference between normal strings and unicode strings? I don't need or want the u.

The only thing I've found that might have helped was the PYTHONIOENCODING environment variable. Unfortunately, setting it to 'ascii' or 'latin-1' doesn't make those u's go away.

I'm using Python 2.6, and I use either the regular python interpreter, or iPython.

2 Answers
Related