Hex editor display - can this be more pythonic?

CC crobc at BOGUS.sbcglobal.net
Mon Jul 30 03:30:22 CEST 2007


Dennis Lee Bieber wrote:
> On Sun, 29 Jul 2007 12:24:56 -0700, CC <crobc at BOGUS.sbcglobal.net>
> declaimed the following in comp.lang.python:
>>for c in ln:
>>     if c in printable: sys.stdout.write(c)
>>     else:
>>         sys.stdout.write('\x1B[31m.')
>>         sys.stdout.write('\x1B[0m')
> 	Be aware that this does require having a terminal that understands
> the escape sequences (which, to my understanding, means unusable on a
> WinXP console window)

Yeah, with this I'm not that concerned about Windows.  Though, can WinXP 
still load the ansi.sys driver?

>>Thus, I might display data something like this:
>>
>>00(\0) 01() FF() 20( ) 34(4) 35(5) 36(6) 08(\b) 38(8) 39(9) 61(a) 62(b) 
>>63(c) 64(d) 65(e) 7E(~)
>>
> 	UGH!

:-D  Lovely isn't it?

> 	If the original "hex bytes    dotted ASCII" side by side isn't
> workable, I'd suggest going double line...
> 
> 	00  01  FF  20  34  35  36  08  38  39  61  62  63  64  65  7E
> 	nul soh xFF sp   4   5   6  bs   8   9   a   b   c   d   e   ~

Yeah, something like that is probably nicer.

> Use the standard "name" for the control codes (though I shortened
> "space" to "sp", and maybe just duplicate the hex for non-named,
> non-printable, codes (mostly those in the x80-xFF range, unless you are
> NOT using ASCII but something like ISO-Latin-1

I've got a lot to learn about this encoding business.

> 	To allow for the names, means using a field width of four. Using a
> line width of 16-data bytes makes for an edit window width of 64, and
> you could fit a hex offset at the left of each line to indicate what
> part of the file is being worked.

Right.


Thanks for the reply!


-- 
_____________________
Christopher R. Carlen
crobc at bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5



More information about the Python-list mailing list