[IPython-user] Can I configure ipython to output hex format for number?

Ville M. Vainio vivainio@gmail....
Tue Sep 23 03:36:47 CDT 2008


On Tue, Sep 23, 2008 at 9:46 AM, Wong, Shin Guey
<shin.guey.wong@intel.com> wrote:

> I am using ipython to do some hardware validating stuff and require to read a lot of hex number. I have a lot functions which only return decimal value but when the ipython print it out at the console, I would like it to change it to hex format when it detected the return string is number. Is this doable in ipython?

Yes. You can create a new result-displayer for integers by doing this:

from IPython.generics import result_display

def print_hex(i):
  print hex(i)

print_hex = result_display.when_type(int)(print_hex)

You might want to add this to your ipy_user_conf.py. Actually, this
may be a good example to add to the documentation as well.

-- 
Ville M. Vainio
http://tinyurl.com/vainio


More information about the IPython-user mailing list