New submission from steven Michalske <smichal...@gmail.com>:

It is a common practice to separate hex digits with a "thousands" separator 
every 4 hex digits.

0x1234_abcd

Although python does not accept the _ as a thousands separator in hex notation, 
neither is the thousands separator in base 10


Snippet that prints hex thousands with a _ separator

number = 0xef5678abcd1234

def hex_thousands(number):
    txt="{0:X}".format(number)
    txt_out = ""
    i = range(-4,-1 * (len(txt) + 4), -4)
    ii = i[:]
    ii.insert(0, None)
    for (j, k) in zip(i, ii):
        if txt_out:
            txt_out = "_" + txt_out
        txt_out = txt[j:k] + txt_out
    return txt_out

print hex_thousands(number)

----------
messages: 100422
nosy: hardkrash
severity: normal
status: open
title: PEP 3101 string formatting missing hexadecimal separator _ for every 4 
hex digits
versions: Python 2.7, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8062>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to