Colored representation of objects in IPython terminal shell -
if want have colored representation of objects in qtconsole or ipython notebook, have add _repr_html_ method objects class.
in [1]: class test(object):             def __init__(self, x):                 self.x = x              def _repr_html_(self):                 return '''<span style="color: green">                        test{<span style="color: red">%s</span>}                        </span>''' % self.x in [2]: test(33) test{33} this give me nice colored representation test{ green, 33 red , } green again.
is there way in terminal version of ipython shell in cross platform way?
ideally work same way the templates prompt customization:
in [1]: class test(object):             def __init__(self, x):                 self.x = x              def _repr_shell_(self):                 return '{color.green}test{{color.red}%s{color.green}}' % self.x if not, can somehow import , use ipython's internal cross-platform coloring system in own console application? looked ipython codebase, haven't found direct way use :(
you can use termcolors ipython.
 minimal example be:
from ipython.utils.coloransi import termcolors color class test(object):    def __init__(self, x):        self.x = x    def __repr__(self):        return '{0}test{{{1}{2}{0}}}'.format(color.green, color.red, self.x) 
Comments
Post a Comment