A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-February/077115.html below:

[Python-Dev] Backporting PEP 3127 to trunk

[Python-Dev] Backporting PEP 3127 to trunk [Python-Dev] Backporting PEP 3127 to trunkBernhard Herzog bh at intevation.de
Fri Feb 22 21:42:01 CET 2008
Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> I don't know about oct(), but I found hex() to be quite useful
> the other day when I was using the interactive interpreter to
> to some hex calculations. It would have been quite tedious
> having to say "%x".format(_) or some such all the time to
> see the results in hex.
>
> An alternative might be to have some variable that can be
> set to control the format of numbers printed by the interactive
> shell.

Something like this?

>>> import sys
>>> import __builtin__
>>> def myhook(o):
...     if isinstance(o, int):
...             print hex(o)
...     else:
...             print repr(o)
...     __builtin__._ = o
...
>>> sys.displayhook = myhook
>>> 123
0x7b


   Bernhard
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4