Re: Hex editor display - can this be more pythonic?

2007-07-30 Thread Neil Cerutti
On 2007-07-30, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Sun, 29 Jul 2007 18:30:22 -0700, CC <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> >> Yeah, with this I'm not that concerned about Windows. Though, can WinXP >> still load the ansi.sys driver? >> > I'

Re: Hex editor display - can this be more pythonic?

2007-07-29 Thread Marc 'BlackJack' Rintsch
On Sun, 29 Jul 2007 18:27:25 -0700, CC wrote: > Marc 'BlackJack' Rintsch wrote: >> I'd use `string.printable` and remove the "invisible" characters like '\n' >> or '\t'. > > What is `string.printable` ? There is no printable method to strings, > though I had hoped there would be. I don't yet k

Re: Hex editor display - can this be more pythonic?

2007-07-29 Thread CC
Dennis Lee Bieber wrote: > On Sun, 29 Jul 2007 12:24:56 -0700, CC <[EMAIL PROTECTED]> > 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 a

Re: Hex editor display - can this be more pythonic?

2007-07-29 Thread CC
Marc 'BlackJack' Rintsch wrote: > On Sun, 29 Jul 2007 12:24:56 -0700, CC wrote: >>The next step consists of printing out the ASCII printable characters. >>I have devised the following silliness: >> >>printable = ' >>[EMAIL PROTECTED]&8*9(0)aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\ >>`

Re: Hex editor display - can this be more pythonic?

2007-07-29 Thread Marc 'BlackJack' Rintsch
On Sun, 29 Jul 2007 12:24:56 -0700, CC wrote: > ln = '\x00\x01\xFF 456\x0889abcde~' > import sys > for c in ln: > sys.stdout.write( '%.2X ' % ord(c) ) > > or this: > > sys.stdout.write( ' '.join( ['%.2X' % ord(c) for c in ln] ) + ' ' ) > > Either of these produces the desired output: > >

Hex editor display - can this be more pythonic?

2007-07-29 Thread CC
Hi: I'm building a hex line editor as a first real Python programming exercise. Yesterday I posted about how to print the hex bytes of a string. There are two decent options: ln = '\x00\x01\xFF 456\x0889abcde~' import sys for c in ln: sys.stdout.write( '%.2X ' % ord(c) ) or this: sys.st