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

Wong, Shin Guey shin.guey.wong@intel....
Tue Sep 23 07:36:55 CDT 2008


Thanks and it works!!! Appreciate for your help. :)
I think most ppl should like to have this kind of tweak and I agree that it should add in the documentation.

Regards,
Shin Guey


>-----Original Message-----
>From: Ville M. Vainio [mailto:vivainio@gmail.com]
>Sent: Tuesday, September 23, 2008 4:37 PM
>To: Wong, Shin Guey
>Cc: ipython-user@scipy.org
>Subject: Re: [IPython-user] Can I configure ipython to output hex format
>for number?
>
>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