This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients ezio.melotti, pitrou, serhiy.storchaka, techtonik
Date 2013-05-04.09:42:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1367660578.42.0.494949959363.issue17868@psf.upfronthosting.co.za>
In-reply-to
Content
>  1) A separate function might be better.  I think this kind of output would be more useful while inspecting individual byte objects, rather than having it for arbitrary byte objects (that might be inside other containers).

I don't think the general hexdump() function is worth to including in the stdlib. It should have too many options (How many bytes display in one line? How group hexdigits? What replacemant character for non-printables? Whether or not to display addresses? Whether or not to display chars? What are delimiters between hexdigits and chars, address and hexdigits? What are line prefix and suffix? How display last incomplete line? How display first incomplete line?) and this makes it complicated. An application which outputs a hexdump on more rich device (a html file or a ANSI-colored terminal) needs advanced options.

However a simple specialized code can be used for special purposes, i.e. internally in the pprint module. I don't see how it can be reused and don't interested in a general function.

>  2) I don't know if the output of pprint is supposed to be eval()uable, but I don't like too much the base64.b16decode(...).replace(' ', '') in the output (especially if the byte objects are short).  If a separate function is used as suggested in 1) this won't be a problem.  Using the hex_codec might be another option.

An alternative option is first output a bytes object as is (perhaps splitting it on multiple line as in issue17530) and then output a hexdamp as a comment.

[b'\x7fELF\x01\x01\x01\x00\x00\n'
 b'\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00\x01'
 # 7F 45 4C 46 01 01 01 00 00 0A 00 00 00 00 00 00 | .ELF............
 # 02 00 03 00 01                                  | .....
 ]
History
Date User Action Args
2013-05-04 09:42:58serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, techtonik, ezio.melotti
2013-05-04 09:42:58serhiy.storchakasetmessageid: <1367660578.42.0.494949959363.issue17868@psf.upfronthosting.co.za>
2013-05-04 09:42:58serhiy.storchakalinkissue17868 messages
2013-05-04 09:42:57serhiy.storchakacreate