如何在所有ipython输出中添加.decode(“unicode-escape”)?

时间:2014-05-07 17:01:57

标签: ipython python-unicode

在python和ipython中:

In [1]: complex_object = ['test', u'тест']

In [2]: print(complex_object)
['test', u'\u0442\u0435\u0441\u0442']

In [3]: complex_object
Out[3]: ['test', u'\u0442\u0435\u0441\u0442']

In [4]: print(complex_object[1])
тест

In [5]: complex_object[1]
Out[5]: u'\u0442\u0435\u0441\u0442'

In [6]: print(complex_object.__repr__().decode("unicode-escape"))
['test', u'тест']

我怎样才能将ipython配置为始终输出如下变量:

In [1]: complex_object = ['test', u'тест']

In [2]: complex_object
['test', u'тест']

我找到的只是:

$ grep -n print_method core/formatters.py
216:       :attr:`print_method`. If is does, that object is passed to that method
236:    print_method = ObjectName('__repr__')
...

并且没有更多文档

0 个答案:

没有答案